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

CS604 Assignment 2docx

The document outlines a system with three processes and three resource types, detailing the total resources, allocation matrix, and maximum demand matrix. It applies the Banker's Algorithm to determine the initial available resources and need matrix, concluding that the system is safe with a unique safe sequence of P1 -> P2 -> P0. All processes can complete without causing a deadlock.

Uploaded by

salmanabbas731
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

CS604 Assignment 2docx

The document outlines a system with three processes and three resource types, detailing the total resources, allocation matrix, and maximum demand matrix. It applies the Banker's Algorithm to determine the initial available resources and need matrix, concluding that the system is safe with a unique safe sequence of P1 -> P2 -> P0. All processes can complete without causing a deadlock.

Uploaded by

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

Muhammad Salman Abbas

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

Maximum Demand (Max) Matrix:


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

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

Therefore, Available = Total Resources - Total Allocated


= (7, 2, 3) - (5, 1, 3)
= (2, 1, 0)

Calculate the Need matrix:


The Need matrix shows how much more of each resource each process needs to complete its
execution.
Need Matrix = Maximum Demand - Allocation Matrix

Maximum Demand (Max) Matrix:


A B C
6 1 2
3 1 2
5 0 2
Allocation Matrix:
A B C
0 1 0
2 0 1
3 0 2
Need Matrix:
A B C
6-0 1-1 2-0
3-2 1-0 2-1
5-3 0-0 2-2

= A B C
6 0 2
1 1 1
2 0 0

Part 2: Determine if the current system state is safe


To determine if the current system state is safe, we will use Banker's Algorithm to find a safe
sequence.

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]

Step 2: Process P1 (since Need[1] <= Available)


Need[1] = (1, 1, 1)
Available = Available + Allocation[1] = (2, 1, 0) + (2, 0, 1) = (4, 1, 1)
Finish[1] = true
Safe sequence: P1

Step 3: Process P2 (since Need[2] <= Available)


Need[2] = (2, 0, 0)
Available = Available + Allocation[2] = (4, 1, 1) + (3, 0, 2) = (7, 1, 3)
Finish[2] = true
Safe sequence: P1 -> P2

Step 4: Process P0 (since Need[0] <= Available)


Need[0] = (6, 0, 2)
Available = Available + Allocation[0] = (7, 1, 3) + (0, 1, 0) = (7, 2, 3)
Finish[0] = true
Safe sequence: P1 -> P2 -> P0

Therefore, The system is safe, and the unique safe sequence is P1 -> P2 -> P0.
*All processes can finish without causing a deadlock.

You might also like