CS604 Assignment 2 Solution (Cs604)
CS604 Assignment 2 Solution (Cs604)
ID: BC230208018
Name: Muhammad Talha Bin Rashid
Question :
Analyze the current state of a system based on the following data, which includes:
a) The available system resources,
b) The resources already allocated to each process,
c) The new resource requests made by each of the five processes (P0, P1, P2, P3, and P4).
Determine whether the system is in a safe state using the Banker’s Algorithm.
Given Data:
Available: A = 3, B = 2, C = 2
Allocation:
P0 = [0, 1, 0]
P1 = [2, 0, 0]
P2 = [3, 0, 3]
P3 = [2, 1, 1]
P4 = [0, 0, 2]
Request:
P0 = [0, 0, 1]
P1 = [2, 0, 2]
P2 = [0, 0, 0]
P3 = [1, 0, 0]
P4 = [0, 0, 2]
Solution;
Total Intialy Available Resources Before Allocation;Allocation =Available
A B C
10 4 8
Allocation:
Process A B C
P0 0 1 0
P1 2 0 0
P2 3 0 3
P3 2 1 1
P4 0 0 2
Request :
Process A B C
P0 0 0 1
P1 2 0 2
P2 0 0 0
P3 1 0 0
P4 0 0 2
Step 2:
Deriving the Max Matrix
The Max Matrix is calculated as:
Max = Allocation + Request
Step 3:
Calculate the Need Matrix
The Need Matrix is calculated as:
Need = Max - Allocation
Process P0 :
Need A B C
P0 0 0 1
Process Finish
P0 True
Check each process to see if it can complete with the current resources:
Process P1 :
Need A B C
P1 2 0 2
Process Finish
P0 True
P1 True
Safe Sequence < P0,P1>
Check each process to see if it can complete with the current Work resources:
Process P2 :
Need A B C
P2 0 0 0
Process Finish
P0 True
P1 True
P2 True
Safe Sequence < P0,P1,P2>
Check each process to see if it can complete with the current Work resources:
Process P3:
Need A B C
P3 1 0 0
Resource A B C
work 10 4 6
Safe Sequence
Safe Sequence: < P0,P1,P2,P3>
Safe State : Yes