Bankers Algorithm - Soln
Bankers Algorithm - Soln
search_query=bankers+algorithm+for+deadlock+avoidance
Need = Max-Allocation
Need
Processes A B C D
P0 0 1 0 0
P1 0 4 2 1
P2 1 0 0 1
P3 0 0 2 0
P4 0 6 4 2
Work=Available
Work=Work+Allocation(Pi)
P0
Finish(P0)=False
0,1,0,0<=1,5,2,0 = true
Finish(P0)=true
Work=1,6,3,0
P1
Finish(P1)=False
Need (P1)<=Work
0,4,2,1<=1,6,3,0 = False
Need = Max-Allocation
Need
Processes A B C D
P0 0 1 0 0
P1 0 4 2 1
P2 1 0 0 1
P3 0 0 2 0
P4 0 6 4 2
Work=1,6,3,0
P2
Finish(P2)=False
Need (P2)<=Work
1,0,0,1<=1,6,3,0 = False
Work=1,6,3,0
P3
Finish(P3)=False
Need (P3)<=Work
0,0,2,0<=1,6,3,0 = True
Finish(P3)=True
Work = 1, 12, 6, 2
P4
Finish(P4)=False
Need (P4)<=Work
0,6,4,2<=1,12,6,2 = True
Finish(P4)=True
Need = Max-Allocation
Need
Processes A B C D
P0 0 1 0 0
P1 0 4 2 1
P2 1 0 0 1
P3 0 0 2 0
P4 0 6 4 2
Work=1, 12, 7, 6
P1
Finish(P1)=False
Need (P1)<=Work
Finish(P1)=true
P2
Finish(P2)=False
Need (P2)<=Work
Finish(p2)=True
Work = 3, 17, 16, 12
Need = Max-Allocation
Need
Processes A B C D
P0 0 1 0 0
P1 0 4 2 1
P2 1 0 0 1
P3 0 0 2 0
P4 0 6 4 2
Request 1: P2(1, 2, 1, 1)
Request 2: P1(0, 2, 1, 0)
Ex for Lab:
Q2:
5 Pen drives
2 Printers
4 Scanners
3 Hard disks
Here, we have created a vector representing total resources: Available = (5, 2, 4, 3).
Assume there are four processes. The available resources are already allocated as per the matrix table below.