Spring 2024 - CS604 - 2
Spring 2024 - CS604 - 2
Assignment # 02
Spring 2024
Student ID: BC220401817
Question Statement 20 marks
Consider a system with three processes (P0, P1, P2) and three resource types (A, B, C). The system is described by the
following data:
Total Resources:
A B C
7 2 3
Allocation Matrix
A B C
P0 0 1 0
P1 2 0 1
P2 3 0 2
Part 2:
Determine if the current system state is safe or not?
If it is safe, provide the unique safe sequence.
If it is not, then justify your answer.
Solution:
Part 1:
1. Calculate the initial available resources.
Total Resources:
A: 7
B: 2
C: 3
[ ]
A B C
0 1 0
Allocation Matrix:
2 0 1
3 0 2
To calculate the available resources, we first sum up the resources allocated to all processes:
Allocated resources:
A: 0 + 2 + 3 = 5
B: 1 + 0 + 0 = 1
C: 0 + 1 + 2 = 3
[ ]
A B C
6 1 2
Maximum Demand Matrix (Max):
3 1 2
5 0 2
[ ]
A B C
0 1 0
Allocation Matrix:
2 0 1
3 0 2
[ ][ ]
A B C A B C
6 1 2 0 1 0
= −
3 1 2 2 0 1
5 0 2 3 0 2
[ ]
A B C
6 0 2
=
1 1 1
2 0 0
Part 2:
Determine if the current system state is in safe state or not, provide the unique safe sequence if in safe state.
Initial Available Resources: [ 2 1 0 ]
[ ]
6 0 2
Need Matrix: 1 1 1
2 0 0
[ ]
0 1 0
Allocation Matrix: 2 0 1
3 0 2
Check P0:
Need: [6, 0, 2]
Available: [2, 1, 0]
Since, Need 0 <= Available is false, P0 cannot proceed.
Check P1:
Need: [1, 1, 1]
Available: [2, 1, 0]
Since, Need 1 <= Available is false, P1 cannot proceed.
Check P2:
Need: [2, 0, 0]
Available: [2, 1, 0]
Since, Need 2 <= Available is true, P2 can proceed.
After P2 finishes, it releases its resources: [3, 0, 2]
New available resources: [2+3, 1+0, 0+2] = [5, 1, 2]
Check P0 again:
Need: [6, 0, 2]
Available: [5, 1, 2]
Since, Need 0 <= Available is false, P0 cannot proceed.
Check P1 again:
Need: [1, 1, 1]
Available: [2, 1, 0]
Since, Need 1 <= Available is true, P1 can proceed.
After P1 finishes, it releases its resources: [2, 0, 1]
New available resources: [5+2, 1+0, 2+1] = [7, 1, 3]
Check P0 again:
Need: [6, 0, 2]
Available: [7, 1, 3]
Since, Need 0 <= Available is true, P0 can proceed.
After P0 finishes, it releases its resources: [0, 1, 0]
New available resources: [7+0, 1+1, 3+0] = [7, 2, 3]
Since all processes can finish, the system is in a safe state. The safe sequence is:
{P2, P1, P0}