CS604 Assignment No 2 BC200407881
CS604 Assignment No 2 BC200407881
2
BC200407881
Question No. 1
Part 1:
1. Calculate Initial Available Resources
The available resources are calculated as the total resources minus the allocated resources for
each resource type.
Total Resources:
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
A: 0 + 2 + 3 = 5
B: 1 + 0 + 0 = 1
C: 0 + 1 + 2 = 3
Available resources
A = Total_A - Allocated_A = 7 - 5 = 2
B = Total_B - Allocated_B = 2 - 1 = 1
C = Total_C - Allocated_C = 3 - 3 = 0
So, the initial available resources are
Available = [2, 1, 0]
The Need matrix is calculated as the Max matrix minus the Allocation matrix.
A B C
P0 6 1 2
P1 3 1 2
P2 5 0 2
Allocation Matrix
A B C
P0 0 1 0
P1 2 0 1
P2 3 0 2
Need Matrix
A B C
P0 6-0 1-1 2-0
P1 3-2 1-0 2-1
P2 5-3 0-0 2-2
A B C
P0 6 0 2
P1 1 1 1
P2 2 0 0
Part 2
Safety Algorithm:
1. Initialize:
o Work = Available = [2, 1, 0]
o Finish = [False, False, False]
2. Find an i such that:
o Finish[i] == False
o Need[i] <= Work
o If no such i exists, go to step 4
3. If such an i is found:
o Work = Work + Allocation[i]
o Finish[i] = True
o Go to step 2
4. If Finish[i] == True for all i, the system is in a safe state
Let's apply these steps
Initial Work = [2, 1, 0]
Safe Sequence:
The safe sequence is P1, P2, P0.
Need Matrix:
A B C
P0 6 0 2
P1 1 1 1
P2 2 0 0