edited by
11,601 views
21 votes
21 votes

In a system, there are three types of resources: $E, F$ and $G$. Four processes $P_0$, $P_1$, $P_2$ and $P_3$ execute concurrently. At the outset, the processes have declared their maximum resource requirements using a matrix named Max as given below. For example, Max[$P_2, F$] is the maximum number of instances of $F$ that $P_2$ would require. The number of instances of the resources allocated to the various processes at any given state is given by a matrix named Allocation.

Consider a state of the system with the Allocation matrix as shown below, and in which $3$ instances of $E$ and $3$ instances of $F$ are only resources available.

$$ \begin{array}{|l|}\hline \textbf{Allocation}   \\\hline & \text{E} & \text{F} & \text{G}  \\\hline  \text{$P_0$} & \text{1} & \text{0} & \text{1} \\\hline  \text{$P_1$} & \text{1} & \text{1}  & \text{2}\\\hline  \text{$P_2$} & \text{1} & \text{0}  & \text{3}\\\hline  \text{$P_3$} & \text{2} & \text{0}  & \text{0}\\\hline \end{array} \begin{array}{|l|}\hline \textbf{Max}   \\\hline & \text{E} & \text{F} & \text{G}  \\\hline  \text{$P_0$} & \text{4} & \text{3} & \text{1} \\\hline  \text{$P_1$} & \text{2} & \text{1}  & \text{4}\\\hline  \text{$P_2$} & \text{1} & \text{3}  & \text{3}\\\hline  \text{$P_3$} & \text{5} & \text{4}  & \text{1}\\\hline \end{array} $$

From the perspective of deadlock avoidance, which one of the following is true?

  1. The system is in $safe$ state
  2. The system is not in $safe$ state, but would be $safe$ if one more instance of $E$ were available
  3. The system is not in $safe$ state, but would be $safe$ if one more instance of $F$ were available
  4. The system is not in $safe$ state, but would be $safe$ if one more instance of $G$ were available
edited by

3 Answers

Best answer
26 votes
26 votes
$$ \begin{array}{|l|}\hline \textbf{Allocation}   \\\hline\text{Process}  & \text{E} & \text{F} & \text{G}  \\\hline   \text{$P_0$} & \text{1} & \text{0} & \text{1} \\\hline  \text{$P_1$} & \text{1} & \text{1}  & \text{2}\\\hline  \text{$P_2$} & \text{1} & \text{0}  & \text{3}\\\hline  \text{$P_3$} & \text{2} & \text{0}  & \text{0}\\\hline \end{array} \begin{array}{|l|}\hline \textbf{Max}   \\\hline \text{Process}& \text{E} & \text{F} & \text{G}  \\\hline  \text{$P_0$} & \text{4} & \text{3} & \text{1} \\\hline  \text{$P_1$} & \text{2} & \text{1}  & \text{4}\\\hline  \text{$P_2$} & \text{1} & \text{3}  & \text{3}\\\hline  \text{$P_3$} & \text{5} & \text{4}  & \text{1}\\\hline \end{array} \begin{array}{|l|}\hline \textbf{Need=Max-Allocation}   \\\hline\text{Process}& \text{E} & \text{F} & \text{G}  \\\hline  \text{$P_0$} & \text{3} & \text{3} & \text{0} \\\hline  \text{$P_1$} & \text{1} & \text{0}  & \text{2}\\\hline  \text{$P_2$} & \text{0} & \text{3}  & \text{0}\\\hline  \text{$P_3$} & \text{3} & \text{4}  & \text{1}\\\hline \end{array}$$

Available Resource $[E,F,G] = $  $(3,3,0)$
With $(3,3,0)$ we can satisfy the request of either $P_0$ or $P_2$.

Let's assume request of $P_0$  satisfied.
After execution, it will release resources.
Available Resource $=(3,3,0) + (1,0,1) = (4,3,1)$

Give $(0,3,0)$ out of $(4,3,1)$ unit of resources to $P_2$ and $P_2$ will completes its execution.
After execution, it will release resources.
Available Resource $=(4,3,1)+(1,0,3) =(5,3,4)$

Allocate $(1,0,2)$ out of $(5,3,4)$ unit of resources to $P_1$ and $P_1$ will completes its execution.
After execution, it will release resources.
Available Resource $=(5,3,4)+(1,1,2) = (6,4,6)$
And finally, allocate resources to $P_3$.

So, we have one of the possible safe sequence: $P_0\longrightarrow P_2\longrightarrow P_1\longrightarrow P_3$

Correct Answer: $A$
edited by
0 votes
0 votes

PROCESS

ALLOCATION

MAXIMUM

NEED

AVAILABLE

P0

1           0          1

4          3           1

3            3              0

3        3            0

P1

1           1          2

1          1           2

2             0             2

 

P2

1           0          3

1           0          3 

0             3             0

 

P3

2          0           0

2           0          0

3             4             1

 
         

 (3,3,0) we can satisfy the request of either P0 or P2.

If we take P0 then 
we have (4,3,1)


 now, take P2  then we have (5, 3, 4)


now, take  P1 then we have (6, 4,6) 


now, allocate all resources to P3


execution order will be P0----->P2------.>P1-------->P3

and given system is in the safe state 

option a is the correct answer.

edited by
Answer:

Related questions

34 votes
34 votes
5 answers
1