4
190kviews
Consider the following snapshot of a system

enter image description here

With reference to Bankers algorithm

i) What is the content of the matrix need ?

ii) Is the system in a safe state?

iii) If a request from process P1 arrives for (0,4,2,0),can the request be granted immediately?

1 Answer
38
34kviews

Need matrix is calculated by subtracting Allocation Matrix from the Max matrix

enter image description here

To check if system is in a safe state

  • The Available matrix is $[1 5 2 0]$.
  • A process after it has finished execution is supposed to free up all the resources it hold.
  • We need to find a safety sequence such that it satisfies the criteria need $Need ≤ Available$.
  • Since $Need(P0) ≤ Available$ , we select $P0. [Available]=[Available]+[Allocation(P0)]$

$Available= [1 5 2 0]+ [0 0 1 2]=[1 5 3 2]$

  • Need(P2) ≤ Available $→$Available=[1 5 3 2]+[1 3 5 4]=[2 8 8 6]
  • Need(P3) ≤ Available$→$ Available=[ 2 8 8 6 ]+[ 0 6 3 2 ]=[2 14 11 8 ]
  • Need(P4) ≤ Available$→$Available=[ 2 14 11 8 ]+[0 0 1 4 ]=[ 2 14 12 12 ]
  • Need(P1) ≤ Available$→$Available=[ 2 14 12 12 ]+[ 1 0 0 0 ]=[ 3 14 12 12]
  • Safe Sequence is <p0,p2,p3,p4,p1>

A request from process P1 arrives for (0,4,2,0)

  • System receives a request for P1 for $Req(P1)[ 0 4 2 0 ]$
  • First we check if Req(P1) is less than $Need(P1) $→$ [ 0 4 2 0 ]\lt [ 0 7 5 0 ] is true$
  • Now we check if Req(P1) is less than $Available $→$[0 4 2 0]\lt[1 5 2 0] is true$.
  • So we update the values as:
    • $Available=Available-Request=[ 1 5 2 0 ]- [ 0 4 2 0 ]=[ 1 1 0 0 ]$
    • $Allocation=allocation(P1)+Request= [ 1 0 0 0 ]+[ 0 4 2 0]=[ 1 4 2 0 ]$
    • $Need= Need(P1)-Request=[ 0 7 5 0 ]- [ 0 4 2 0]=[0 3 3 0 ]$

enter image description here

  • This is the modified table
  • On verifying, we see that the safe sequence still remains the same .The system continues to remain in a safe state.
Please log in to add an answer.