0% found this document useful (0 votes)
8 views

CS604 Assignment No 2 BC200407881

Uploaded by

someworking
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

CS604 Assignment No 2 BC200407881

Uploaded by

someworking
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

CS604 Assignment No.

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

Sum of allocations for each resource type

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]

2. Calculate the Need Matrix

The Need matrix is calculated as the Max matrix minus the Allocation matrix.

Maximum Demand (Max) 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

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]
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]

Since Finish = [True, True, True], the system is in a safe state.

Safe Sequence:
The safe sequence is P1, P2, P0.

 Initial Available Resources: [2, 1, 0]

 Need Matrix:
A B C
P0 6 0 2
P1 1 1 1
P2 2 0 0

System State: Safe

You might also like