Consider the following snapshot of a system: (10pts) Process Allocation Max Avai
ID: 3571798 • Letter: C
Question
Consider the following snapshot of a system: (10pts)
Process Allocation Max Available
A B C D A B C D A B C D
P0 1 2 0 1 1 6 6 2 0 2 2 0
P1 1 0 0 1 1 1 0 1
P2 0 4 4 0 1 4 4 2
P3 0 0 0 2 0 0 2 3
P4 1 0 0 1 3 7 4 4
a) Is the system in a safe state (Use algorithm to show it) ?
b) Is a request from Process P4 arrives for (0, 1, 0, 0) can the request be granted immediately (Use the data to show it) ?
c) Is a request from Process P4 arrives for (0, 0, 1, 0) can the request be granted immediately (Use the data to show it)?
Explanation / Answer
Allocation Max Available
A B C D A B C D A B C D
P0 1 2 0 1 1 6 6 2 0 2 2 0
P1 1 0 0 1 1 1 0 1
P2 0 4 4 0 1 4 4 2
P3 0 0 0 2 0 0 2 3
P4 1 0 0 1 3 7 4 4
First Find Need so Need =(Max- Allocation)
A B C D
P0 0 4 6 1
P1 0 1 0 0
P2 1 0 0 2
P3 0 0 2 1
P4 2 7 4 3
Using banker’s algorithm:-
Step 1:
Safety for process P0
need0 = (0, 4, 6, 1)
If need0 Available
if (0, 4, 6, 1) (0, 2, 2,0) (false)
Process P0 must wait.
Step 2:
Safety for process P1
Need1 = (0, 1, 0, 0)
If need1 Available
If (0, 1, 0, 0) (0, 2, 2,0) (true)
P1 will execute.
Available = Available + Allocation
(0, 2, 2,0)+ 1 0 0 1
(1,2,2,1)
Step 3:
Safety for process P2
Need2 = (1, 0, 0, 2)
If need2 Available
If (1, 0, 0, 2) (1, 2, 2,1) (False)
P2 will wait.
Step 4:
Safety for process P3
Need3 = (0, 0, 2, 1)
If need3 Available
If (0, 0, 2, 1) (1, 2, 2,1) (true)
P3 will execute.
Available = Available + Allocation
(1, 2, 2,1) +( 0 0 0 2)
(1,2,2,3)
Step 5:
Safety for process P4
Need4 = (2, 7, 4, 3)
If need4 Available
If (2, 7, 4, 3) (1, 2, 2,3) (False)
P4 will wait
Next p2 will execute.
Step 5:
Safety for process P4
Need2 = (0, 0, 2, 1)
If need2 Available
If (1, 0, 0, 2) (1, 2, 2,3) (False)
P4 will execute
Available = Available + Allocation
(1, 2, 2,3) + (0 4 4 0)
(1,6,6,3)
Next p0 and p4 execute
So sequence is <p1, p3,p2, p0, p4>
System in safe.
---------------------------------------------------------------------------------------------
If you have any query, please feel free to ask.
Thanks a lot.