Operating systems miscellaneous


Operating systems miscellaneous

  1. The P and V operations on counting semaphores, where s is a counting semaphore, and defined as follows P(s): s = s – 1;
        if s < 0 then wait;
    V(s): s = s + 1;
    if s < = 0 then we ke up 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 (Yb);
        s = s + 1;
    if (s < = 0) Vb (Yb);
    Vb (Xb);
    The initial values of Xb and Yb are respectively









  1. View Hint View Answer Discuss in Forum

    From the given code we get that P(S) and V(S), decrement and increment the value of semaphore respectively. So, from the given conditions we conclude that to avoid mutual exclusion in the value of Xb should be 1 and that of Yb should be 0.

    Correct Option: C

    From the given code we get that P(S) and V(S), decrement and increment the value of semaphore respectively. So, from the given conditions we conclude that to avoid mutual exclusion in the value of Xb should be 1 and that of Yb should be 0.


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

    How many times will process P print ‘0’?









  1. View Hint View Answer Discuss in Forum

    P0 uses a semaphore. Hence, anything whose value is 1, P0 will print ‘0’. After the release of S1 and S2, we observe that either P1 or P2 will release S0 so that it print ‘0’ at least 2 times.
    Therefore, it is concluded that neither P1 nor P2 will go, it is the P0 that prints ‘0’ 2 times atleast.

    Correct Option: A

    P0 uses a semaphore. Hence, anything whose value is 1, P0 will print ‘0’. After the release of S1 and S2, we observe that either P1 or P2 will release S0 so that it print ‘0’ at least 2 times.
    Therefore, it is concluded that neither P1 nor P2 will go, it is the P0 that prints ‘0’ 2 times atleast.



  1. 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?









  1. View Hint View Answer Discuss in Forum

    Three concurrent processes X, Y and Z execute three different code segments that access and update certain shared variables.

    (a) X : P(a) P(b) P(c)
    Y : P(b) P(c) P(d)
    Z : P(c) P(d) P(a)
    Suppose X first executes P(a) and P(b) and then switches to process Z, where P(c) and P(d) are executed and wait for P(a), Then again process switches to X and then wait for P(c).
    ∴ Process X is waiting for C which is occupied by Z and Z is waiting for a which is occupied by process X. So, neither can execute and deadlock occurs. (Not Acceptable)
    (b) X : P(b) P(a) P(c)
    Y : P(b) P(c) P(d)
    Z : P(a) P(c) P(d)

    Execution can be carried out in a proper way without deadlock occurance and no wait for any variable in the processer. (Acceptable)
    (c) X : P(b) P(a) P(c)
    Y : P(c) P(b) P(d)
    Z : P(a) P(c) P(d)

    The sequence of variable P(b) and P(c) are reverse and opposite [i.e., P(b) P(c) P(a) and P(a) P(b) P(c)] So, deadlock may occurs in X and Y respectively (Not Acceptable)
    (d)
    X : P(a) P(b) P(c)
    Y : P(c) P(b) P(d)
    Z : P(c) P(d) P(a)

    The sequence of variable P(c) and P(a) are opposite in Z and X. So, deadlock may occur (Not Acceptable) Hence, the answer is (b).

    Correct Option: B

    Three concurrent processes X, Y and Z execute three different code segments that access and update certain shared variables.

    (a) X : P(a) P(b) P(c)
    Y : P(b) P(c) P(d)
    Z : P(c) P(d) P(a)
    Suppose X first executes P(a) and P(b) and then switches to process Z, where P(c) and P(d) are executed and wait for P(a), Then again process switches to X and then wait for P(c).
    ∴ Process X is waiting for C which is occupied by Z and Z is waiting for a which is occupied by process X. So, neither can execute and deadlock occurs. (Not Acceptable)
    (b) X : P(b) P(a) P(c)
    Y : P(b) P(c) P(d)
    Z : P(a) P(c) P(d)

    Execution can be carried out in a proper way without deadlock occurance and no wait for any variable in the processer. (Acceptable)
    (c) X : P(b) P(a) P(c)
    Y : P(c) P(b) P(d)
    Z : P(a) P(c) P(d)

    The sequence of variable P(b) and P(c) are reverse and opposite [i.e., P(b) P(c) P(a) and P(a) P(b) P(c)] So, deadlock may occurs in X and Y respectively (Not Acceptable)
    (d)
    X : P(a) P(b) P(c)
    Y : P(c) P(b) P(d)
    Z : P(c) P(d) P(a)

    The sequence of variable P(c) and P(a) are opposite in Z and X. So, deadlock may occur (Not Acceptable) Hence, the answer is (b).


  1. Two processes X and Y need to access a critical section. Consider the following synchronization construct used by both the processes
    Process X
    /* other code for process X */
    while (true)
    {
      varP = true;
      while (varQ == true)
      {
    /* critical section */
    varP = false;
      }
    }
    /* other code for process X */
    Process Y
    /* other code for process Y */ while (true)
    {
      varQ = true;
     while (varP == true)
       {
      /* critical section */
    varQ = false;
       }
    }
    /* other code for process Y */
    Here, varP and varQ are shared variables and both are initialized to false. Which one of the following statements is true?









  1. View Hint View Answer Discuss in Forum

    varP = varQ = FALSE Initially.
    Assume that, process X is willing to enter into critical section. So it makes varP = True, then if processor switches to process Y, then process Y can enter into critical section.
    After entering into the critical section, then if processor switches to process X, then process X also can enter into the critical section. It is clearly showing that both are in critical section at a time which leads to “failing to guarantee material exclusion”
    To enter into the critical section process X is not waiting for process Y and vice versa. So we can “Prevent Deadlock” so, overall, option (a) is correct.

    Correct Option: A

    varP = varQ = FALSE Initially.
    Assume that, process X is willing to enter into critical section. So it makes varP = True, then if processor switches to process Y, then process Y can enter into critical section.
    After entering into the critical section, then if processor switches to process X, then process X also can enter into the critical section. It is clearly showing that both are in critical section at a time which leads to “failing to guarantee material exclusion”
    To enter into the critical section process X is not waiting for process Y and vice versa. So we can “Prevent Deadlock” so, overall, option (a) is correct.



  1. Consider the intermediate code given below.
    (1) i = 1 (2) j = 1
    (3) t1 = 5 * i (4) t2 = t1 + j
    (5) t3 = 4 * t2 (6) t4 = t3
    (7) a[t4] = – 1 (8) j = j + 1
    (9) if j < = 5 goto (3) (10) i = i + 1
    (11) if i < 5 goto (2)

    The number of nodes and edges in the control-flow-graph constructed for the above code, respectively, are









  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: B

    NA