edited by
755 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$
edited by

1 Answer

Best answer
0 votes
0 votes

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
Answer:

Related questions

2 votes
2 votes
1 answer
1
Bikram asked Dec 26, 2016
282 views
Consider the following 3 processes with 3 binary semaphores with initial values $S_{0}=0, S_{1}=0, S_{2}=1$$$ \begin{array}{|c|c|c|} \hline \textbf{P} & \textbf{Q} & \tex...
2 votes
2 votes
3 answers
2
Bikram asked Dec 26, 2016
1,113 views
In a paged memory, the page hit ratio is $0.35$. The time required to service the page fault is $100$ ns. Time required to access a page in primary memory is $10$ ns.The ...
1 votes
1 votes
1 answer
4
Bikram asked Dec 26, 2016
215 views
A counting semaphore is initialized to $10$. The $6$ P(wait) operations and $4$ V(signal) operations were completed in this semaphore. The resulting value of semaphore is...