GATE Questions & Answers of Inter-Process Communication, Concurrency and Synchronization

What is the Weightage of Inter-Process Communication, Concurrency and Synchronization in GATE Exam?

Total 18 Questions have been asked from Inter-Process Communication, Concurrency and Synchronization topic of Operating System subject in previous GATE papers. Average marks 1.72.

The following C program is executed on a Unix/Linux system:

#include <unistd.h>

int main()


int i;

for (i=0; i<10; i++)

if (i%2 == 0) fork();

return 0;


The total number of child processes created is ________. 

Consider three concurrent processes P1, P2 and P3 as shown below, which access a shared variable D that has been initialized to 100.

P1 P2 P3
$:$ $:$ $:$
$:$ $:$ $:$
D = D + 20 D = D – 50 D = D + 10
$:$ $:$ $:$
$:$ $:$ $:$


The processes are executed on a uniprocessor system running a time-shared operating system. If the minimum and maximum possible values of D after the three processes have completed execution are X and Y respectively, then the value of Y – X is _____________.


Consider the following snapshot of a system running n concurrent processes. Process i is holding Xi instances of a resource R, $ 1\leq i\leq n. $ Assume that all instances of R are currently in use. Further, for all i, process i can place a request for at most Yi additional instances of R while holding the Xi instances it already has. Of the n processes, there are exactly two processes p and q such that Yp = Yq = 0. Which one of the following conditions guarantees that no other process apart from p and q can complete execution?

Consider the following solution to the producer-consumer synchronization problem. The shared buffer size is N. Three semaphores empty, full and mutex are defined with respective initial values of 0, N and 1. Semaphore empty denotes the number of available slots in the buffer, for the consumer to read from. Semaphore full denotes the number of available slots in the buffer, for the producer to write to. The placeholder variables, denoted by P, Q, R, and S, in the code below can be assigned either empty or full. The valid semaphore operations are: wait() and signal().
Producer: Consumer:
    //Add item to buffer
     //Consume item from buffer

Which one of the following assignments to P, Q, R and S will yield the correct solution?

Consider the following proposed solution for the critical section problem. There are $n$ processes: $ P_0\;...\;P_{n-1}\;. $ In the code, function pmax returns an integer not smaller than any of its arguments. For all $i$, t[i] is initialized to zero.

Code for $P_i:$
do {
      c[i]=1; t[i] = pmax(t[0],...,t[n-1])+1; c[i]=0;
     for every j≠i
in {0,...,n-1} {

         while (c[j]);
         while (t[j] != 0 && t[j]<=t[i]);
     Critical Section;
      Remainder Section;
} while (true);

Which one of the following is TRUE about the above solution?

Consider the following two-process synchronization solution.
Process 0   Process 1
---------   ----------
Entry: loop while (turn == 1);   Entry: loop while (turn == 0);
(critical section)   (critical section)
Exit: turn = 1;   Exit: turn = 0;


The shared variable turn is initialized to zero. Which one of the following is TRUE?

Consider a non-negative counting semaphore S. The operation P(S) decrements S, and V(S) increments S. During an execution, 20 P(S) operations and 12 V(S) operations are issued in some order. The largest initial value of S for which at least one P(S) operation will remain blocked is ______.

The following two functions P1 and P2 that share a variable B with an initial value of 2 execute concurrently.


The number of distinct values that B can possibly take after the execution is__________.

A variable x is said to be live at a statement Si in a program if the following three conditions hold simultaneously:
i. There exists a statement Sj that uses x
ii. There is a path from Si to Sj in the flow graph corresponding to the program
iii. The path has no intervening assignment to x including at Si and Sj

The variables which are live both at the statement in basic block 2 and at the statement in basic block 3 of the above control flow graph are


Three concurrent processes X, Y, and Z execute three different code segments that access and update certain shared variables. Process X executes the P operation (i.e., wait) on semaphores a, b and c; process Y executes the P operation on semaphores b, c and d; process Z executes the P operation on semaphores c, d, and a before entering the respective code segments. After completing the execution of its code segment, each process invokes the V operation (i.e., signal) on its three semaphores. All semaphores are binary semaphores initialized to one. Which one of the following represents a deadlock-free order of invoking the P operations by the processes?

A shared variable x, initialized to zero, is operated on by four concurrent processes W, X, Y, Z as follows. Each of the processes W and X reads x from memory, increments by one, stores it to memory, and then terminates. Each of the processes Y and Z reads x from memory, decrements by two, stores it to memory, and then terminates. Each process before reading x invokes the P operation (i.e., wait) on a counting semaphore S and invokes the V operation (i.e., signal) on the semaphore S after storing x to memory. Semaphore S is initialized to two. What is the maximum possible value of x after all processes complete execution?

A certain computation generates two arrays a and b such that a[i]=f(i) for 0 ≤ i < n and b[i] = g (a[i]) for 0 ≤ i < n. Suppose this computation is decomposed into two concurrent processes X and Y such that X computes the array a and Y computes the array b. The processes employ two binary semaphores R and S, both initialized to zero. The array a is shared by the two processes. The structures of the processes are shown below.

          Process X:
private i;
for (i=0; i<n; i++) {
a[i] = f(i);
ExitX(R, S);
Process Y:
private i;
for (i=0; i<n; i++) {
EntryY(R, S);
b[i] = g(a[i]);

Which one of the following represents the CORRECT implementations of ExitX and EntryY?

Fetch_And_Add(X,i) is an atomic Read-Modify-Write instruction that reads the value of memory location X, increments it by the value i, and returns the old value of X. It is used in the pseudocode shown below to implement a busy-wait lock. L is an unsigned integer shared variable initialized to 0. The value of 0 corresponds to lock being available, while any non-zero value corresponds to the lock being not available.

          while (Fetch_And_Add(L,1))
                  L = 1;
          L = 0;

This implementation

Consider the methods used by processes P1 and P2 for accessing their critical sections whenever needed, as given below. The initial values of shared Boolean variables S1 and S2 are randomly assigned.

Method used by PI Method used by P2
while (S1 = = S2) ;
Critical Section
S1 = S2;
while (S1 != S2) ;
 Critical section
 S2 = not (S1);

Which one of the following statements describes the properties achieved?

The following program consists of 3 concurrent processes and 3 binary semaphores. The semaphores are initialized as S0=1, S1=0, S2=0.

Process P0 Process P1 Process P2
 while (true) {
    wait (S0);
    print ‘0’
    release (S1);
    release (S2);
 wait (S1);
 Release (S0);
 wait (S2);
 release (S0);

How many times will process P0 print ‘0’?

The enter_CS() and leave_CS() functions to implement critical section of a process are realized using test-and-set instruction as follows:

void enter_CS(X)
             while (test-and-set(X)) ;
void leave_CS(X)

In the above solution, X is a memory location associated with the CS and is initialized to 0. Now consider the following statements:

I. The above solution to CS problem is deadlock-free
II. The solution is starvation free.
III. The processes enter CS in FIFO order.
IV. More than one process can enter CS at the same time.

Which of the above statements are TRUE?

The P and V operations on counting semaphores, where s is a counting semaphore, are defined as follows:
P(s) : s = s - 1;
      if s < 0 then wait;
V(s) : s = s + 1;
     if s <= 0 then wakeup a process waiting on s;
Assume that Pb and Vb the wait and signal operations on binary semaphores are provided. Two binary semaphores xb and yb are used to implement the semaphore operations P(s) and V(s) as follows:

P(s) : Pb (xb);
       s = s -1;
       if (s < 0) {
         Vb (xb);
         Pb (yb);
       else Vb (xb);
V(s) : Pb (xb);
       s = s + 1;
       if (s <=0) Vb (yb);
         Vb (xb);

The initial values of xb and yb are respectively

Two processes, P1 and P2, need to access a critical section of code. Consider the following synchronization construct used by the processes:

Here, wants1 and wants2 are shared variables, which are initialized to false. Which one of the following statements is TRUE about the above construct?