Consider a system with 5 processes P0 through P4 and three resource types A, B and C. The following snapshot of the system has been taken
| Allocation | Max | Available | |||||||
| A | B | C | A | B | C | A | B | C | |
| P0 | 0 | 1 | 0 | 7 | 5 | 3 | 3 | 3 | 2 |
| P1 | 2 | 0 | 0 | 3 | 2 | 2 | |||
| P2 | 3 | 0 | 2 | 9 | 0 | 2 | |||
| P3 | 2 | 1 | 1 | 2 | 2 | 2 | |||
| P4 | 0 | 0 | 2 | 4 | 3 | 3 | |||
- Find the need matrix.
- Is the system safe? Explain.
Banker’s Algorithm: Need Matrix and Safe State Check (BTech CSE, Operating Systems)
Given
Processes: P0–P4; Resource types: A, B, C
Available (A, B, C) = (3, 3, 2)
Allocation and Max (from the snapshot):
Process Allocation (A B C) Max (A B C) P0 (0 1 0) (7 5 3) P1 (2 0 0) (3 2 2) P2 (3 0 2) (9 0 2) P3 (2 1 1) (2 2 2) P4 (0 0 2) (4 3 3)
1) Need Matrix (Need = Max − Allocation)
Process Need (A B C) P0 (7 4 3) = (7 5 3) − (0 1 0) P1 (1 2 2) = (3 2 2) − (2 0 0) P2 (6 0 0) = (9 0 2) − (3 0 2) P3 (0 1 1) = (2 2 2) − (2 1 1) P4 (4 3 1) = (4 3 3) − (0 0 2)
2) Safety Check using Banker’s Algorithm
Initial Work = Available = (3, 3, 2)
-
Find a process whose Need ≤ Work:
- P1 Need (1,2,2) ≤ (3,3,2) → safe to run
-
With Work = (5,3,2), choose:
- P3 Need (0,1,1) ≤ (5,3,2) → run P3
-
With Work = (7,4,3), choose:
- P0 Need (7,4,3) ≤ (7,4,3) → run P0
-
With Work = (7,5,3), choose:
- P2 Need (6,0,0) ≤ (7,5,3) → run P2
-
With Work = (10,5,5), choose:
- P4 Need (4,3,1) ≤ (10,5,5) → run P4
Conclusion
- Need Matrix:
P0 (7,4,3), P1 (1,2,2), P2 (6,0,0), P3 (0,1,1), P4 (4,3,1) - Safe Sequence found:
P1 → P3 → P0 → P2 → P4
- Therefore, the system is in a safe state because every process can finish in the above order without causing deadlock.
