Operating systems miscellaneous


Operating systems miscellaneous

  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. 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. 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. Consider two processes P1 and P2 accessing the shared variables X and Y protected by two binary semaphores Sx and Sy respectively, both initialized to 1. P and V denote the usual semaphore operators, where P decrements the semaphore value, and V increments the semaphore value. The pseudo-code of P1 and P2 is as follows :

    In order to avoid deadlock, the correct operators at L1, L2, L3 and L4 are respectively









  1. View Hint View Answer Discuss in Forum

    Here semaphores are required to obtain mutual exclusion since both access X & Y. So at L1 P(Sx) which means now Sx = wait at L2 P(Sy) Sy wait, this prevents process P2 to start access X &Y. V(Sx) & V(Sy) in the end of P1 makes Sx & Sy signal so that at L3 & L4 P(Sx) & P(Sy) can start. Hence (d) is correct option.

    Correct Option: D

    Here semaphores are required to obtain mutual exclusion since both access X & Y. So at L1 P(Sx) which means now Sx = wait at L2 P(Sy) Sy wait, this prevents process P2 to start access X &Y. V(Sx) & V(Sy) in the end of P1 makes Sx & Sy signal so that at L3 & L4 P(Sx) & P(Sy) can start. Hence (d) is correct option.



Direction: Suppose we want to synchronize two concurrent processes P and Q using binary semaphores S and T. The code for the processes P and Q is shown below:

Process P Process Q
while (1) { while (1) {
W: Y:
print ‘0’; print ‘1’
print ‘0’; print ‘1’
X: Z:
}

Synchronization statement can be inserted only at point W, X, Y and Z

  1. Which of the following will always lead to an output string with ‘001100110011’?









  1. View Hint View Answer Discuss in Forum

    For output string 001100110011 alternatingly we require process P & Q to execute. For this to happen P(s) with S = 1 should be placed at W. At the same time P(T) with T = 0 will be at Y.
    At X we have V(T) which will have T = 1 so process Q starts.
    At the same time at Z we have V(s) which make S = 0 to stop process P.
    Hence (b) is correct option.

    Correct Option: B

    For output string 001100110011 alternatingly we require process P & Q to execute. For this to happen P(s) with S = 1 should be placed at W. At the same time P(T) with T = 0 will be at Y.
    At X we have V(T) which will have T = 1 so process Q starts.
    At the same time at Z we have V(s) which make S = 0 to stop process P.
    Hence (b) is correct option.