CS FundamentalsHardGATE CS (PYQ pattern)

Semaphores a = 1, b = 0, c = 0. Four processes each run once: P1: wait(a); print 1; signal(b); signal(c). P2: wait(b); print 2; signal(a). P3: wait(c); print 3; signal(a). P4: wait(a); print 4. All four start together. Which statement is correct?

  1. A. Exactly 6 different complete outputs exist, and some schedules deadlock
  2. B. Exactly 4 different complete outputs exist, and some schedules deadlock
  3. C. Exactly 4 different complete outputs exist, and no schedule can deadlock
  4. D. Exactly 3 different complete outputs exist, and some schedules deadlock

Correct answer: B. Exactly 4 different complete outputs exist, and some schedules deadlock

Only one wait(a) can succeed first. If P4 wins, a stays 0 and P1 blocks forever (deadlock). If P1 wins, 1 is followed by an order of 2, 3, 4 where 4 needs a signal(a) from 2 or 3: 1234, 1243, 1324, 1342.

More Operating Systems questions

Exams that ask this topic