Operating systems miscellaneous


Operating systems miscellaneous

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 ensure that the output string never contains a substring of the form 01n 0 or 10n1 where n is odd?









  1. View Hint View Answer Discuss in Forum

    To ensure this condition that substring of form 01n0 or 10n1, where n is odd S should be initially 1, we will case only 1 semaphore S.
    So at W P(s), at X V(s) whereas at Y P(s), at Z V(s) Hence (c) is correct option.

    Correct Option: C

    To ensure this condition that substring of form 01n0 or 10n1, where n is odd S should be initially 1, we will case only 1 semaphore S.
    So at W P(s), at X V(s) whereas at Y P(s), at Z V(s) Hence (c) is correct option.


  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.



  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.


  1. Two processes P1 and P2, need to access a critical section of code. Consider the following synchronization construct used by the processes :
    /* P1 *//* P2 */
    while (true) { while (true){
    wants1 = true; wants2 = true;
    while while (wants 1 = = true);
    (wants2 = = true); /* Critical
    /* Critical Section */
    Section */ wants2 = false;
    wants1 = false;   } /* Remainder section */
    } (/* Remainder Section)

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









  1. View Hint View Answer Discuss in Forum

    Wants2 enters the critical section, if process P1 ’s variable wants1 is true and if wants2 is true then wants1 enters critical section. In both cases, there will be deadlock but no mutual exclusion.

    Correct Option: D

    Wants2 enters the critical section, if process P1 ’s variable wants1 is true and if wants2 is true then wants1 enters critical section. In both cases, there will be deadlock but no mutual exclusion.



  1. Which of the following system calls results in the sending of SYN packets?









  1. View Hint View Answer Discuss in Forum

    socket() creates a new socket of a certain socket type, identified by an integer number, and allocates system resources to it. bind() is typically used on the server side, and associates a socket with a socket address structure, i.e. a specified local port number and IP address. listen() is used on the server side, and causes a bound TCP socket to enter listening state. connect() is used on the client side, and assigns a free local port number to a socket. In case of a TCP socket, it causes an attempt to establish a new TCP connection. When connect() is called by client, following three way handshake happens to establish the connection in TCP.
    (1) The client requests a connection by sending a SYN (synchronize) message to the server.
    (2) The server acknowledges this request by sending SYN-ACK back to the client.
    (3) The client responds with an ACK, and the connection is established.

    Correct Option: D

    socket() creates a new socket of a certain socket type, identified by an integer number, and allocates system resources to it. bind() is typically used on the server side, and associates a socket with a socket address structure, i.e. a specified local port number and IP address. listen() is used on the server side, and causes a bound TCP socket to enter listening state. connect() is used on the client side, and assigns a free local port number to a socket. In case of a TCP socket, it causes an attempt to establish a new TCP connection. When connect() is called by client, following three way handshake happens to establish the connection in TCP.
    (1) The client requests a connection by sending a SYN (synchronize) message to the server.
    (2) The server acknowledges this request by sending SYN-ACK back to the client.
    (3) The client responds with an ACK, and the connection is established.