100% found this document useful (1 vote)
355 views

CS604 Assignment 2 Solution Spring 2024

Uploaded by

Ahmad Baig
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
355 views

CS604 Assignment 2 Solution Spring 2024

Uploaded by

Ahmad Baig
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

CS604 ASSIGNMENT 2 SOLUTION SPRING 2024

Due Date: 24-June-2024 Total


Marks:

DO NOT COPY PASTE

FOR CORRECT SOLUTION CONTACT WHATSAPP +923162965677

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

Maximum Demand (Max) Matrix:


A B C
P0 6 1 2
P1 3 1 2
P2 5 0 2

JOIN WHATSAPP GROUP

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:

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

JOIN WHATSAPP GROUP

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

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

JOIN WHATSAPP GROUP

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]

JOIN WHATSAPP GROUP

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]

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]

JOIN WHATSAPP GROUP


https://chat.whatsapp.com/IF8sHHq2GYz8BJwG9XEJB1
 Need Matrix:
A B C
P0 6 0 2
P1 1 1 1
P2 2 0 0

System State: Safe

JOIN WHATSAPP GROUP


https://chat.whatsapp.com/IF8sHHq2GYz8BJwG9XEJB1
REGARD - SARIM
WHATSAPP +923162965677

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.

FOR FREE ASSIGNMENTS SOLUTIONS VISIT

VUStudentspk.com

JOIN WHATSAPP GROUP

https://chat.whatsapp.com/IF8sHHq2GYz8BJwG9XEJB1

You might also like