CS604 Assignment 2 Solution Spring 2024
CS604 Assignment 2 Solution Spring 2024
Question:
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
https://chat.whatsapp.com/IF8sHHq2GYz8BJwG9XEJB1
Solve the below parts using Banker’s Algorithm (Safety Algorithm).
Part 1:
1. Calculate the initial available resources.
2. Calculate the Need matrix.
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:
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
https://chat.whatsapp.com/IF8sHHq2GYz8BJwG9XEJB1
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
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
https://chat.whatsapp.com/IF8sHHq2GYz8BJwG9XEJB1
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:
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:
Determine if the System State is Safe
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]
https://chat.whatsapp.com/IF8sHHq2GYz8BJwG9XEJB1
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]
Finish = [False, False, False]
Step 1:
P1's Need (1, 1, 1) <= Work (2, 1, 0)
Work = Work + Allocation of P1 = [2, 1, 0] + [2, 0, 1] = [4, 1, 1]
Finish = [False, True, False]
Step 2:
P2's Need (2, 0, 0) <= Work (4, 1, 1)
Work = Work + Allocation of P2 = [4, 1, 1] + [3, 0, 2] = [7, 1, 3]
Finish = [False, True, True]
Step 3:
P0's Need (6, 0, 2) <= Work (7, 1, 3)
Work = Work + Allocation of P0 = [7, 1, 3] + [0, 1, 0] = [7, 2, 3]
Finish = [True, True, True]
Safe Sequence:
The safe sequence is P1, P2, P0.
PLEASE NOTE:
Don't copy-paste the same answer.
Make sure you can make some changes to your solution file before submitting copy
paste solution will be marked zero.
If you found any mistake then correct yourself and inform me.
Before submitting an assignment must check your assignment requirement file.
If you need some help or question about file and solutions feel free to ask.
VUStudentspk.com
https://chat.whatsapp.com/IF8sHHq2GYz8BJwG9XEJB1