Skip to content
Official PYQ · 2007

GATE CS 2007 Q57 — Deadlock

Explain with AI

A single processor system has three resource types X,YX, Y and ZZ, which are shared by three processes. There are 55 units of each resource type. Consider the following scenario, where the column alloc denotes the number of units of each resource type allocated to each process, and the column request denotes the number of units of each resource type requested by a process in order to complete execution. Which of these processes will finish LAST?

alloc requestXYZXYZP0121103P1201012P2221120\begin{array}{|l|lll|lll|}\hline &\text{} \rlap{\textbf{alloc}} &&&\rlap{ \textbf{request}} \\ \hline &\text{X} & \text{Y} & \text{Z} &\text{X} & \text{Y} & \text{Z} \\ \hline \textbf{P0} & \text{1} & \text{2} & \text{1}& \text{1} & \text{0} & \text{3} \\ \hline \textbf{P1} & \text{2} & \text{0} & \text{1} & \text{0} & \text{1} & \text{2} \\ \hline \textbf{P2} & \text{2} & \text{2} & \text{1} & \text{1} & \text{2} & \text{0} \\ \hline \end{array}

Choose one option
View worked solution

Answer: C

To find the order in which the processes finish, we first calculate the total allocated resources and the initially available resources.

1. Calculate Available Resources:

  • Total resources: X=5,Y=5,Z=5X = 5, Y = 5, Z = 5
  • Total allocated resources:
    • X=1+2+2=5X = 1 + 2 + 2 = 5
    • Y=2+0+2=4Y = 2 + 0 + 2 = 4
    • Z=1+1+1=3Z = 1 + 1 + 1 = 3
  • Available=Total−Allocated=[5−5,5−4,5−3]=[0,1,2]\text{Available} = \text{Total} - \text{Allocated} = [5-5, 5-4, 5-3] = [0, 1, 2]

2. Step-by-Step Execution:

  1. Compare requests with the current available resources [0,1,2][0, 1, 2]:
    • P0P0 request [1,0,3][1, 0, 3] cannot be satisfied.
    • P1P1 request [0,1,2][0, 1, 2] can be satisfied.
    • P2P2 request [1,2,0][1, 2, 0] cannot be satisfied.
    Thus, P1P1 runs first. After completion, it releases its allocated resources [2,0,1][2, 0, 1].
    New Available=[0,1,2]+[2,0,1]=[2,1,3]\text{New Available} = [0, 1, 2] + [2, 0, 1] = [2, 1, 3].
  2. Compare remaining requests with available resources [2,1,3][2, 1, 3]:
    • P0P0 request [1,0,3][1, 0, 3] can be satisfied.
    • P2P2 request [1,2,0][1, 2, 0] cannot be satisfied (2>12 > 1 for resource YY).
    Thus, P0P0 runs next. After completion, it releases its allocated resources [1,2,1][1, 2, 1].
    New Available=[2,1,3]+[1,2,1]=[3,3,4]\text{New Available} = [2, 1, 3] + [1, 2, 1] = [3, 3, 4].
  3. Finally, P2P2 request [1,2,0][1, 2, 0] can be satisfied with [3,3,4][3, 3, 4]. P2P2 runs and finishes.

The safe sequence of execution is P1→P0→P2P1 \to P0 \to P2. Therefore, P2P2 finishes last.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Deadlock questions