OS Questions Bank UNIT2
OS Questions Bank UNIT2
Write the use of semaphore? And also explain how semaphore works?
1 2 K1
A counting semaphore S is initialized to 10. Then, 6 P operations and 4 V
2 operations are performed on S. What is the final value of S? 2 K3
Process P Process Q
while(1) while(1)
{ {
P(S1); P(S1);
7 2 K3
P(S2); P(S2);
Critical Section Critical Section
V(S1); V(S1);
V(S2); V(S2);
} }
This ensures-
1. 1. Mutual Exclusion 2. Deadlock 3. Starvation but not deadlock
8 Draw the process state diagram and explain each state. 2 K1
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
9 2 K3
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?
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 P1 Method used by P2
while (S1 == S2); while (S1 != S2);
Critical Section Critical Section
10 S1 = S2; S2 = !S1; 2 K3
1. 1. Mutual exclusion but not progress 3. Progress but not mutual exclusion
2.Neither mutual exclusion nor progress 4. Both mutual exclusion and progress
CO: Course Outcome BTL: Bloom's Taxonomy Level MM: Max Marks
Name of Faculty:
Waseem Ahmad