Operating System Cpe343 Sessional 2
Operating System Cpe343 Sessional 2
Q2) [ 1x5 = 5 Marks] Given below is the pseudocode to synchronize processes P1, P2,
P3, P4, P5, and P6 by using three semaphores X, Y and Z that are initialized as follow:
X=0, Y=0, Z= –2. The Operating System can schedule the processes which are ready to
execute in any order. List down at least 5 possible orders of execution in which the
processes can run.
P1 P2 P3 P4 P5 P6
Print P1 Wait(Y) Wait(X) Wait(Z) Print P5 Wait(Y)
Signal(Z) Print P2 Print P3 Print P4 Signal(X) Print P6
Signal(Z) Signal(Y) Signal(Z)
Signal(Y)
Q3) [ 6 Marks] Does Peterson’s Solution satisfies the Bounded-waiting and Progress
requirements? If it does, then prove how, if not then state why not. Here is Peterson’s
Solution:
while (true){
flag[i] = true;
turn = j;
while (flag[j] && turn = = j)
;
/* critical section */
flag[i] = false;
/* remainder section */
}
Q4) [4+2 = 6 Marks] Imagine there are following three processes in our system.
P0 – A file backup batch process
P1 – A user editing a video
P2 – An electricity bill generating and printing process
Available
R1 R2 R3 R4
2 1 0 0
Allocation
R1 R2 R3 R4
P0 0 0 1 0
P1 2 0 0 1
P2 0 1 2 0
Request
R1 R2 R3 R4
P0 2 0 0 1
P1 1 0 1 0
P2 2 1 0 0
a) Determine if the system is in a deadlock state or not. You must show all steps, just
a YES/NO answer will not be accepted.
b) Ignore the above scenario and imagine that all three processes are in deadlock.
What will you do and why to recover from the deadlock?