To solve this, we’ll use the Banker’s Algorithm to determine the order in which processes can safely
execute. The key idea is to:
1. Determine the Available resources.
2. See which process’s Request can be satisfied with Available.
3. If satisfied, simulate its execution by releasing its allocated resources.
4. Repeat until all processes are finished or no progress can be made.
Step 1: Total & Allocated Resources
Total resources:
X=5
Y=5
Z=5
Allocated resources:
P0: 1 2 1
P1: 2 0 1
P2: 2 2 1
Total allocated:
X=1+2+2=5
Y=2+0+2=4
Z=1+1+1=3
Step 2: Calculate Available Resources
Available = Total - Allocated =
X=5-5=0
Y=5-4=1
Z=5-3=2
So, Available = (0, 1, 2)
Step 3: Safe Sequence
Now check each process:
Try P0: Request = (1, 0, 3)
Not enough Z (needs 3, only 2 available) → ❌
Try P1: Request = (0, 1, 2)
Needs (0,1,2) ≤ (0,1,2) ✅
→ Can finish. After finishing, releases (2,0,1)
New Available = (0+2, 1+0, 2+1) = (2,1,3)
Try P0 again: Request = (1, 0, 3)
Needs (1,0,3) ≤ (2,1,3) ✅
→ Can finish. Releases (1,2,1)
New Available = (2+1, 1+2, 3+1) = (3,3,4)
Now P2: Request = (1,2,0)
Needs ≤ Available ✅
→ Can finish
Final Order of Execution:
P1 → P0 → P2
Thus, P2 finishes last.
Correct Answer: 3. P2.
Question :A system has 3 resource types: A, B, and C. There are 10, 5, and 7 instances of each
resource, respectively. There are 5 processes (P0–P4). The following tables show the Allocation and
Maximum resource needs for each process:
Allocation Matrix:
Process A B C
P0 010
P1 200
P2 302
P3 211
P4 002
Maximum Matrix:
Process A B C
P0 753
P1 322
P2 902
P3 222
P4 433
Question:
1. Calculate the Available resources.
2. Determine the Need matrix.
3. Is the system in a safe state? If so, find the safe sequence.
Solution:
🔹 Given:
Total Resources:
A = 10
B=5
C=7
Step 1: Calculate Total Allocation
Process ABC
P0 010
P1 200
P2 302
P3 211
P4 002
Total Allocated:
A = 0+2+3+2+0 = 7
B = 1+0+0+1+0 = 2
C = 0+0+2+1+2 = 5
Step 2: Calculate Available Resources
Available = Total - Allocated
A = 10 - 7 = 3
B=5-2=3
C=7-5=2
Available = (3, 3, 2)
Step 3: Calculate Need Matrix
Need = Maximum - Allocation
Process A B C
P0 7-0 = 7 5-1 = 4 3-0 = 3
P1 3-2 = 1 2-0 = 2 2-0 = 2
P2 9-3 = 6 0-0 = 0 2-2 = 0
P3 2-2 = 0 2-1 = 1 2-1 = 1
P4 4-0 = 4 3-0 = 3 3-2 = 1
Step 4: Find Safe Sequence
Start with Available = (3, 3, 2)
Try P1: Need = (1, 2, 2) → ✅ YES
→ After finish: Available += Allocated = (3+2, 3+0, 2+0) = (5, 3, 2)
Try P3: Need = (0,1,1) → ✅ YES
→ After finish: Available += (2,1,1) = (7, 4, 3)
Try P4: Need = (4,3,1) → ✅ YES
→ After finish: Available += (0,0,2) = (7, 4, 5)
Try P0: Need = (7,4,3) → ✅ YES
→ After finish: Available += (0,1,0) = (7, 5, 5)
Try P2: Need = (6,0,0) → ✅ YES
→ After finish: Available += (3,0,2) = (10, 5, 7)
✅ Safe Sequence:
P1 → P3 → P4 → P0 → P2
Question:
System:
Total resources: A = 7, B = 2, C = 6
Processes: P0, P1, P2
Allocation Matrix:
Process A B C
P0 010
P1 201
P2 303
Maximum Matrix:
Process A B C
P0 312
P1 413
P2 315
Questions:
1. Calculate the Available resources.
2. Compute the Need matrix.
3. Determine if the system is in a safe state and find one or more safe sequences.
📗 Example 2: 4 Processes, 3 Resource Types
System:
Total resources: A = 10, B = 5, C = 8
Processes: P0, P1, P2, P3
Allocation Matrix:
Process A B C
P0 010
P1 200
P2 303
P3 211
Maximum Matrix:
Process A B C
P0 632
P1 322
P2 904
P3 422
Questions:
1. Calculate the Available vector.
2. Derive the Need matrix.
3. Check if a safe sequence exists. If yes, find it.