CS604 Assignment 2docx
CS604 Assignment 2docx
BC240217235
BSIT
CS604 (Assignment # 2)
Question Statement
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.
Part 1: Initial Available Resources and Need Matrix
Solution:
Calculate the initial available resources:
Total resources: A = 7, B = 2, C = 3
Allocation Matrix:
A B C
0 1 0
2 0 1
3 0 2
Total allocated resources:
A=0+2+3=5
B=1+0+0=1
C=0+1+2=3
= A B C
6 0 2
1 1 1
2 0 0
Initialize:
Work = Available
Finish[i] = false for all i (processes)
Find an i such that both:
Finish[i] == false
Need[i] <= Work
If such i is found:
Work += Allocation[i]
Finish[i] = true
Add i to the safe sequence
Repeat until all processes are in the safe sequence or no such i is found.
Initial Setup:
Available = (2, 1, 0)
Need Matrix:
A B C
0 1 0
2 0 1
3 0 2
Allocation Matrix:
A B C
6 0 2
1 1 1
2 0 0
Step 1: Initial State
Available = (2, 1, 0)
Finish = [false, false, false]
Therefore, The system is safe, and the unique safe sequence is P1 -> P2 -> P0.
*All processes can finish without causing a deadlock.