in Operating System edited by
759 views
3 votes
3 votes

Consider a system with five processes $P0$ to $P4$ and three resources $R1$, $R2$ and $R3$, each having $10, \ 5, \ 7$ instances respectively. The system table at time $T0$ is shown below:

$$\textbf{Allocation}\\ \begin{array}{|c|c|c|} \hline & R1 & R2 & R3  \\ \hline P0 & 0 & 1 & 0 \\ \hline P1 & 2 & 0 & 0 \\ \hline P2 & 3 & 0 & 2\\ \hline P3 & 2 & 1 &1 \\ \hline P4 & 0 & 0 & 2  \\ \hline  \end{array}$$

$$\textbf{MaX}\\ \begin{array}{|c|c|c|} \hline R1 & R2 & R3  \\ \hline  7 & 5 & 3 \\ \hline  3 & 2 & 2  \\ \hline  9 & 0 & 2\\ \hline  2 & 2 & 2 \\ \hline 4 & 3 & 3 \\ \hline  \end{array}$$

$$\textbf{Available}\\ \begin{array}{|c|c|c|} \hline R1 & R2 & R3  \\ \hline  3 & 3 & 2 \\ \hline  \end{array}$$

Which of the following execution sequences ensure safety in the system?

  1. $P1, P3, P4, P2, P0$
  2. $P1, P4, P2, P3, P0$
  3. $P3, P1, P2, P4, P0$
  4. $P1, P4, P3, P0, P2$
in Operating System edited by
by
759 views

2 Comments

This is the suggested video from "what to read series by bikram sir" of IITKGP PK Biswas.
The same example starts at 9:33 and P0 is chosen over P2 22:50.
@bikram sir which one to choose galvin(no reason is given to choose why to min, one i.e. P2 before P0) or this professor (which is working according to algorithm he explained (I think he too referring from Galvin) before 9:33)

0
0
@bikram sir if we apply bankers algorithm
Option c is also valid.
–1
–1

1 Answer

0 votes
0 votes
Best answer

There are 3 rules for Safety Algorithm:

1.  we calculate Available resources ( in a Matrix structure )

2. Need <=(less than and equal to) Available 

3. Available =  available + Allocation

now calculate need matrix here by this, Need = maximum - allocation 

Need 

A B C 

7 4  3

1 2  2 

6  0 0

0  1 1

4  3  1 

$$\textbf{Need}\\ \begin{array}{|c|c|c|} \hline A & B & C  \\ \hline  7 & 4 & 3 \\ \hline 1 & 2 & 2 \\ \hline 6 & 0 & 0 \\ \hline 0 & 1 & 1 \\ \hline 4 & 3 & 1 \\ \hline  \end{array}$$

so  for P0 Need is NOT less than available, it moves to P1  here need is ( 1,2,2) and available is (3,3,2) 

so for P1, need < available , P1 is in safe sequence . <P1>

now ADD allocation of P1 into available ( 2,0,0 + 3,3,2 ) = ( 5,3,2 ) is our new Available . so P2 can not satisfy , P3 can satisfy ( 0 ,1,1 < 5,3,2 )  now safe sequence becomes < P1 , P3> , available is now  (7,4,3)

P4 next  satisfy,   safe sequence becomes < P1 , P3, P4 > , available is now  (7,4,5)

P2 comes again , as P2 have (6,0,0) which is less than (7,4,3) in P0 , now safe sequence becomes < P1 , P3, P4 , P2 > available is now  (10,4,7) 

P0 is left , it comes , safe sequence becomes < P1 , P3, P4 , P2 , P0 > available is (10, 5, 7 ) 

this way we proceed and final safe  sequence becomes < P1 , P3, P4 , P2 , P0 > . 

edited by

4 Comments

A,C,D options(except option B) satisfy for safety in the system
1
1
@BIKRAM SIR

options a,c,d all are correct except option B. So i think the question should be "Which of the following excuion sequence doesn't ensures safety in the system?"
0
0

@Bikram sir

can I select option (d) as It is also correct sequence?

0
0
Answer:

Related questions