GATE CS 2026 Set 2 | Question 51

Operating Systems › Process Synchronization · MSQ · 2 marks · Answer: A, B, C

  1. Question 51Operating Systemsmsq2 marks
    Consider three processes P1, P2, P3 running identical code. and are binary semaphores initialized to 1 and 0; is a shared variable initialized to 0. Each line executes atomically.
    Wait(A);
    Print(*);
    X = X+1;
    If (X == 2) {
       Print($);
       Signal(B);
    }
    Signal(A);
    Wait(B);
    Print(#);
    Signal(B);
    Any process may start first and context switches may occur at any time. Which of the following patterns is/are possible outcomes?
    • A.
      **$*###
      ✓
    • B.
      **$#*##
      ✓
    • C.
      **$##*#
      ✓
    • D.
      ***$###

    Answer: A, B, C

    Solution

    Answer: (A), (B), (C) Semaphore serializes the Print(*); X=X+1 section, so the three * are printed one at a time. The second process to enter the section makes and prints $ immediately after its * (and Signal(B)), so the output always begins with **$. The remaining * (third process) and the three # (released one-by-one by ) can interleave in several ways — options (A), (B), (C) are all realizable. Option (D) ***$### needs all three * before $, impossible since $ is printed right after the second *.

More GATE PYQ on Process Synchronization

All GATE CS Operating Systems PYQ →

Attempt GATE CS 2026 Set 2 in real GATE exam mode

Full paper with a timer, the GATE interface and a topic-wise analysis — free.

Create free account →