Computer Sciences > GATE 2026 SET-2 > Operating System
Consider three processes P1, P2, and P3 running identical code, as shown in the pseudocode below. A and B are two binary semaphores initialized to 1 and 0, respectively. X is a shared variable initialized to 0. Each line in the pseudocode is executed atomically.
Pseudocode of P1, P2, and P3
Assume that any of the three processes can start to execute first and context switching can happen between these processes at any arbitrary time and in any arbitrary order.
Which of the following patterns is/are possible to be generated as an outcome of the execution of these three processes?
A
**$#*#*#*
B
**$#*#*#*
C
**$#*#*#*
D
***$#*#*#*

Correct : a,b,c

All three processes run the same code. A = 1, B = 0, X = 0 initially.
How it flows
Only one process can pass Wait(A) at a time since A is binary. The 1st process prints , makes X = 1, skips the if-block, calls Signal(A), then blocks at Wait(B) since B = 0.
The 2nd process prints , makes X = 2, enters the if-block, prints $, calls Signal(B) which unblocks the 1st process, then calls Signal(A).
The 1st process now prints # and calls Signal(B). The 3rd process prints *, makes X = 3, skips the if-block, then waits on B and eventually prints #.
Why D is impossible
D requires three * prints before .Butthe3rdprocesscannotenteruntilthe2ndcallsSignal(A),whichhappensonlyafter. But the 3rd process cannot enter until the 2nd calls Signal(A), which happens only after .Butthe3rdprocesscannotenteruntilthe2ndcallsSignal(A),whichhappensonlyafter is already printed. So ***$ can never happen.
Why A, B, C are possible
The 3rd process's * can appear before the first #, between the two # prints, or after both — depending on scheduling. All three give valid distinct patterns, making A, B, and C all possible.
Correct answer: A, B, C ✓

Similar Questions

Consider the following five disk five disk access requests of the form (request id, cylinder number) that are present in the disk scheduler queue at a given tim...
#276 MCQ
Which one of the following CPU scheduling algorithms cannot be preemptive?
#1568 MCQ
To keep track of free blocks in a file system, one of the two approaches is generally used – using bitmaps (bit vectors) or using linked lists. Consider that...
#1599 Fill in the Blanks

Related Topics

binary semaphore GATE 2026 GATE CS 2026 Set-2 Q51 P1 P2 P3 output patterns semaphore process synchronization GATE 2026 binary semaphore A=1 B=0 shared variable operating system GATE 2026 possible output patterns semaphore

Unique Visitor Count

Total Unique Visitors

Loading......