Deadlock Avoidance using Banker’s Algorithm
Q1: Use the following information and complete the Table, also write down the safe sequence if exist?
Three Resources (R1=4, R2=9, R3=11)
Processes |
Allocated Resources R1 R2 R3 |
Maximum Required Resources R1 R2 R3 |
Currently Available Resources R1 R2 R3 |
Remaining Need R1 R2 R3 |
Safe Sequence |
P1 |
1 4 2 |
2 4 6 |
|||
P2 |
2 1 1 |
3 2 8 |
|||
P3 |
0 0 1 |
1 2 3 |
|||
P4 |
0 0 0 |
4 4 2 |
Equations involved in bankers algorithm are
Need Matrix = max resources - allocated resources
Available Resources = Total resources - sum of allocated resources for each process.
If need <=available Resources , then process can be executed . After execution allocated resources are added to available Resources.
Max Matrix
Process | R1 | R2 | R3 |
P1 | 1 | 0 | 4 |
P2 | 1 | 1 | 7 |
P3 | 1 | 2 | 2 |
P4 | 4 | 4 | 2 |
Available Resources.
R1 = 4-(1+2)= 1
R2=9-(4+1)=4
R3=11-(2+1+1)=7
Checking availability for P1,
1,0,4 <= 1,4,7
So P1 executes, after completion
Available Resources = 2,8,9
Checking availability for P2,
1,1,7<=2,8,9
P2 executes,
After execution available Resources = 4,9,10
Checking availability for P3,
1,2,2 <= 4,9,10
P3 executes,
After execution, available Resources = 4,9,11
Checking availability for P4,
4,4,2 <= 4,9,11
P4 executes.
Safe cycle = P1,P2,P3,p4
Get Answers For Free
Most questions answered within 1 hours.