edited by
501 views
2 votes
2 votes

A uniprocessor system has two resources of type A and B shared by four processes. There are $4$ units of each resource type available after allocation. Let “current” indicate the resources allocated to each process and “Need” indicate the remaining number of resources required by each process for completion. If there exist a safe sequence, then which process will complete last$$\overset{\textbf{Current}}{\begin{array}{|c|c|c|} \hline  & A & B \\ \hline P0 & 2 & 1 \\ \hline P1 & 1 & 2 \\ \hline P2 & 0 & 2 \\ \hline P3 & 1 & 0 \\ \hline  \end{array}} \qquad\overset{\textbf{Need}}{\begin{array}{|c|c|c|} \hline  & A & B \\ \hline P0 & 6 & 2 \\ \hline P1 & 4 & 5 \\ \hline P2 & 3 & 2 \\ \hline P3 & 5 & 6 \\ \hline  \end{array}}$$

  1. $P1$
  2. $P0$
  3. $P3$
  4. No safe sequence exists
edited by

1 Answer

Best answer
2 votes
2 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

so in this question our Allocation matrix and Need matrix are respectively:

     A   B                    A   B
 P0  2   1             P0     6    2
 P1  1   2             P1     4    5
 P2  0   2             P2     3    2 
 P3  1   0             P3     5    6

question says, 

there are 4 units of each resource type is available , so our Available matrix becomes

A  B

4   4  

so start from P0 it have need 6,2 it not satisfy 4,4 which is available. Only P2 satisfy it has 3,2 so our new Available matrix become (4,4 + 0,2) = 4,6 so now P3 can not satisfy it. P0 also can not, P1 have 4,5  it can satisfy.  so now our safe sequence is <P2 , P1> . 

next Available become (4,6 + 1,2)= 5,8 so now P3 comes next , it can satisfy. new Available become 5,8 + 1,0= 6,8 now P0 can satisfy it . so final safe sequence become < P2 , P1. P3, P0 > .

Safe Sequence:  < P2 ,P1 ,P3 ,P0 >  so  P0 will execute last.

selected by
Answer:

Related questions

2 votes
2 votes
1 answer
1
Bikram asked Dec 26, 2016
264 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,051 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
203 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...