Banker’s Algorithm


#1

Consider the following snapshot of Banker’s Algorithm
Customer Allocation Max Need Available


i) Is this system is in a safe state?
ii) Can a request for (0,4,2,0) can be granted


#2

first we need to calculate the need matrix
Need[i,j]=Max[i,j]-Allocation[i,j]
Need Matrix
process Need matrix
A [0 0 0 0]
B [0 7 5 0]
C [1 0 0 2]
D [0 0 2 0]
E [0 6 4 2]
Now to check is the system is in safe state
we need to apply safety algorithm
1)initialize work=Available
finish[i]=false ; for 1,2,…n
2) find i such that
finish[i]=false;
Need[i]<=work
if no such i goto step 4
3) work=work+Allocation[i]
finish[i]=true
goto step (2)
4) if finish[i]=true for all i,
then the system is in safe state
here, work= 1 2 5 0
since need[i]<= work for all customers so
so work=work+ Allocation
A [1 2 5 0]+ [0 0 1 2] = [1 2 6 2]
B [1 2 6 2]+ [1 0 0 0] = [2 2 6 2]
C [2 2 6 2]+ [1 3 5 4]= [3 6 1 6]
D [3 6 1 6]+ [0 6 3 2]= [4 2 4 8]
E [4 2 4 8]+ [0 0 1 4]= [4 2 6 2]
as it satisfies the safety algorithm (true for all customers)
so the safe sequence is
A-> B -> C -> D->E

ii)for request the processor is not specified
for this we need to check resource request algorithm

  1. Request[i]<Need[i]
    goto step (2)
    else error
  2. if request[i] < Available
    goto step (3)otherwise processor must wait since resource not available

Available=Available - request[i]
Allocation[i]=Allocation[i]+Request[i]
Need[i]=Need[i]-Request[i]