Deadlock
Question 1 |

A | |
B | |
C | |
D |
Discuss it
Question 2 |
min (Xp, Xq) < max (Yk) where k != p and k != q | |
Xp + Xq >= min (Yk) where k != p and k != q | |
max (Xp, Xq) > 1 | |
min (Xp, Xq) > 1 |
Discuss it
Question 3 |
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 deadlockfree order of invoking the P operations by the processes? (GATE CS 2013)
X: P(a)P(b)P(c) Y:P(b)P(c)P(d) Z:P(c)P(d)P(a) | |
X: P(b)P(a)P(c) Y:P(b)P(c)P(d) Z:P(a)P(c)P(d) | |
X: P(b)P(a)P(c) Y:P(c)P(b)P(d) Z:P(a)P(c)P(d) | |
X: P(a)P(b)P(c) Y:P(c)P(b)P(d) Z:P(c)P(d)P(a) |
Discuss it
Option A can cause deadlock. Imagine a situation process X has acquired a, process Y has acquired b and process Z has acquired c and d. There is circular wait now. Option C can also cause deadlock. Imagine a situation process X has acquired b, process Y has acquired c and process Z has acquired a. There is circular wait now. Option D can also cause deadlock. Imagine a situation process X has acquired a and b, process Y has acquired c. X and Y circularly waiting for each other. See http://www.eee.metu.edu.tr/~halici/courses/442/Ch5%20Deadlocks.pdf Consider option A) for example here all 3 processes are concurrent so X will get semaphore a, Y will get b and Z will get c, now X is blocked for b, Y is blocked for c, Z gets d and blocked for a. Thus it will lead to deadlock. Similarly one can figure out that for B) completion order is Z,X then Y. This question is duplicate of https://www.geeksforgeeks.org/gate-gate-cs-2013-question-16/ Watch GeeksforGeeks Video Explanation :
Question 4 |
if (i % 2 == 0) { if (i < n) request Ri if (i+2 < n) request Ri+2 } else { if (i < n) request Rn-i if (i+2 < n) request Rn-i-2 }In which one of the following situations is a deadlock possible?
n=40, k=26 | |
n=21, k=12 | |
n=20, k=10 | |
n=41, k=19 |
Discuss it
Option B is answer No. of resources, n = 21 No. of processes, k = 12 Processes {P0, P1....P11} make the following Resource requests: {R0, R20, R2, R18, R4, R16, R6, R14, R8, R12, R10, R10} For example P0 will request R0 (0%2 is = 0 and 0< n=21). Similarly, P10 will request R10. P11 will request R10 as n - i = 21 - 11 = 10. As different processes are requesting the same resource, deadlock may occur.
Question 5 |
Process P1: t=0: requests 2 units of R2 t=1: requests 1 unit of R3 t=3: requests 2 units of R1 t=5: releases 1 unit of R2 and 1 unit of R1. t=7: releases 1 unit of R3 t=8: requests 2 units of R4 t=10: Finishes Process P2: t=0: requests 2 units of R3 t=2: requests 1 unit of R4 t=4: requests 1 unit of R1 t=6: releases 1 unit of R3 t=8: Finishes Process P3: t=0: requests 1 unit of R4 t=2: requests 2 units of R1 t=5: releases 2 units of R1 t=7: requests 1 unit of R2 t=8: requests 1 unit of R3 t=9: FinishesWhich one of the following statements is TRUE if all three processes run concurrently starting at time t=0?
All processes will finish without any deadlock | |
Only P1 and P2 will be in deadlock. | |
Only P1 and P3 will be in a deadlock. | |
All three processes will be in deadlock |
Discuss it
We can apply the following Deadlock Detection algorithm and see that there is no process waiting indefinitely for a resource. See this for deadlock detection algorithm.
Question 6 |
In deadlock prevention, the request for resources is always granted if the resulting state is safe | |
In deadlock avoidance, the request for resources is always granted if the result state is safe | |
Deadlock avoidance is less restrictive than deadlock prevention | |
Deadlock avoidance requires knowledge of resource requirements a priori |
Discuss it
Question 7 |

REQ1: P0 requests 0 units of X, 0 units of Y and 2 units of Z REQ2: P1 requests 2 units of X, 0 units of Y and 0 units of ZWhich one of the following is TRUE?
Only REQ1 can be permitted. | |
Only REQ2 can be permitted. | |
Both REQ1 and REQ2 can be permitted. | |
Neither REQ1 nor REQ2 can be permitted |
Discuss it
AVAILABLE | X=3, Y=2, Z=2 | |
MAX | ALLOCATION | |
X Y Z | X Y Z | |
P0 | 8 4 3 | 0 0 1 |
P1 | 6 2 0 | 3 2 0 |
P2 | 3 3 3 | 2 1 1 |
AVAILABLE | X=3, Y=2, Z=0 | ||
MAX | ALLOCATION | NEED | |
X Y Z | X Y Z | X Y Z | |
P0 | 8 4 3 | 0 0 3 | 8 4 0 |
P1 | 6 2 0 | 3 2 0 | 3 0 0 |
P2 | 3 3 3 | 2 1 1 | 1 2 2 |
AVAILABLE | X=6, Y=4, Z=0 | ||
MAX | ALLOCATION | NEED | |
X Y Z | X Y Z | X Y Z | |
P0 | 8 4 3 | 0 0 3 | 8 4 0 |
P1 | 6 2 0 | 3 2 0 | 0 0 0 |
P2 | 3 3 3 | 2 1 1 | 1 2 2 |
AVAILABLE | X=1, Y=2, Z=2 | ||
MAX | ALLOCATION | NEED | |
X Y Z | X Y Z | X Y Z | |
P0 | 8 4 3 | 0 0 1 | 8 4 2 |
P1 | 6 2 0 | 5 2 0 | 1 0 0 |
P2 | 3 3 3 | 2 1 1 | 1 2 2 |
AVAILABLE | X=7, Y=4, Z=2 | ||
MAX | ALLOCATION | NEED | |
X Y Z | X Y Z | X Y Z | |
P0 | 8 4 3 | 0 0 1 | 8 4 2 |
P1 | 6 2 0 | 5 2 0 | 0 0 0 |
P2 | 3 3 3 | 2 1 1 | 1 2 2 |
AVAILABLE | X=10, Y=7, Z=5 | ||
MAX | ALLOCATION | NEED | |
X Y Z | X Y Z | X Y Z | |
P0 | 8 4 3 | 0 0 1 | 8 4 2 |
P1 | 6 2 0 | 5 2 0 | 0 0 0 |
P2 | 3 3 3 | 2 1 1 | 0 0 0 |
AVAILABLE | X=18, Y=11, Z=8 | ||
MAX | ALLOCATION | NEED | |
X Y Z | X Y Z | X Y Z | |
P0 | 8 4 3 | 0 0 1 | 0 0 0 |
P1 | 6 2 0 | 5 2 0 | 0 0 0 |
P2 | 3 3 3 | 2 1 1 | 0 0 0 |
Question 8 |
6 | |
7 | |
8 | |
9 |
Discuss it
Question 9 |
min (Xp, Xq) < max (Yk) where k != p and k != q | |
Xp + Xq >= min (Yk) where k != p and k != q | |
max (Xp, Xq) > 1 | |
min (Xp, Xq) > 1 |
Discuss it
Question 10 |

A | |
B | |
C | |
D |
Discuss it