A system has three resource types with totals A = 9, B = 4, C = 6 and four processes:
| Process | Allocation (A B C) | Max (A B C) |
|---|---|---|
| P0 | 0 1 0 | 5 3 2 |
| P1 | 2 0 0 | 3 2 2 |
| P2 | 3 0 2 | 4 0 3 |
| P3 | 2 1 1 | 2 2 2 |
Using the Banker's algorithm, is the system in a safe state? If so, give a safe sequence.
Show hints
First compute Available = Total − sum of Allocation, and Need = Max − Allocation.
Show the explanation
Worked answer.
Step 1 — Available
Sum of allocations: A = 0+2+3+2 = 7, B = 1+0+0+1 = 2, C = 0+0+2+1 = 3.
Available = (9−7, 4−2, 6−3) = (2, 2, 3).
Step 2 — Need = Max − Allocation
- P0: (5,3,2) − (0,1,0) = (5, 2, 2)
- P1: (3,2,2) − (2,0,0) = (1, 2, 2)
- P2: (4,0,3) − (3,0,2) = (1, 0, 1)
- P3: (2,2,2) − (2,1,1) = (0, 1, 1)
Step 3 — Safety check (find a process whose Need ≤ Work, let it finish, add its Allocation back to Work)
- Work = (2,2,3). P0 needs A = 5 > 2, not yet. P1 needs (1,2,2) ≤ (2,2,3) ✓ → Work = (2,2,3) + (2,0,0) = (4,2,3).
- P2 needs (1,0,1) ≤ (4,2,3) ✓ → Work = (4,2,3) + (3,0,2) = (7,2,5).
- P3 needs (0,1,1) ≤ (7,2,5) ✓ → Work = (7,2,5) + (2,1,1) = (9,3,6).
- P0 needs (5,2,2) ≤ (9,3,6) ✓ → Work = (9,3,6) + (0,1,0) = (9,4,6).
All processes can finish, so the state is safe, with safe sequence ⟨P1, P2, P3, P0⟩. Work ends equal to the totals (9,4,6), which confirms the arithmetic. Other safe orders also exist (e.g. starting with P2 or P3); any one valid sequence is enough.
Key ideas to state
- A safe state means there exists at least one order in which every process can obtain its maximum demand and finish.
- An unsafe state is not necessarily deadlocked; it only means deadlock can no longer be ruled out.
- For a new request, the algorithm checks Request ≤ Need and Request ≤ Available, pretends to grant it, and runs this safety check; if the result is unsafe, the request waits.
Follow-up: "Why don't real operating systems use Banker's?" It needs each process's maximum demand in advance, a fixed number of processes and resources, and runs in O(m × n²) per request — impractical for general-purpose systems.
Original UniCircle question. Last reviewed 28 Oct 2026.
