0% found this document useful (0 votes)
11 views5 pages

CS604 Assignment 2 Solution (Cs604)

Uploaded by

Umair Ulfat
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)
11 views5 pages

CS604 Assignment 2 Solution (Cs604)

Uploaded by

Umair Ulfat
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/ 5

Assignment 02 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

Process A(Max) B(Max) C(Max)


P0 0 1 1
P1 4 0 2
P2 3 0 3
P3 3 1 1
P4 0 0 4

Step 3:
Calculate the Need Matrix
The Need Matrix is calculated as:
Need = Max - Allocation

Process A (Need) B (Need) C (Need)


P0 0 0 1
P1 2 0 2
P2 0 0 0
P3 1 0 0
P4 0 0 2

At Present Available Resources Table :


Process Allocation Need Available
A B C A B C A B C
P0 0 1 0 0 0 1 3 2 2
P1 2 0 0 2 0 2
P2 3 0 3 0 0 0
P3 2 1 1 1 0 0
P4 0 0 2 0 0 2
Check each process to see if it can complete with the current resources:

 Process P0 :

Need A B C
P0 0 0 1

Need <work is True (because 0 < 3 and 1 < 2).


So P0 , would be the first process for which we fulfilled its need

Updating work by Adding allocation of P0;


Resource A B C
work 3 3 2

Set Finish of P0 to True :

Process Finish
P0 True

Safe Sequence <p>

At Present Available Resources Table :


Process Allocation Need Available
A B C A B C A B C
P1 2 0 0 2 0 2 3 3 2
P2 3 0 3 0 0 0
P3 2 1 1 1 0 0
P4 0 0 2 0 0 2

Check each process to see if it can complete with the current resources:

 Process P1 :
Need A B C
P1 2 0 2

NEED 1 < Work is True


So p1, would be the second process for which we fulfilled its need

Update work by adding Allocation of P1 :


Resource A B C
work 5 3 2
Set Finish of P1 to True :

Process Finish
P0 True
P1 True
Safe Sequence < P0,P1>

At Present Available Resources Table :


Process Allocation Need Available
A B C A B C A B C
P2 3 0 3 0 0 0 5 3 2
P3 2 1 1 1 0 0
P4 0 0 2 0 0 2

Check each process to see if it can complete with the current Work resources:
 Process P2 :
Need A B C
P2 0 0 0

NEED 2 < Work is True


So P2, would be the second process for which we fulfilled its need

Update work by adding Allocation of P2 :


Resource A B C
work 8 3 5

Set Finish of P2 to True :

Process Finish
P0 True
P1 True
P2 True
Safe Sequence < P0,P1,P2>

At Present Available Resources Table :


Process Allocation Need Available
A B C A B C A B C
P3 2 1 1 1 0 0 8 3 5
P4 0 0 2 0 0 2

Check each process to see if it can complete with the current Work resources:

 Process P3:
Need A B C
P3 1 0 0

NEED 3 < Work is True


So P3, would be the second process for which we fulfilled its need

Update work by adding Allocation of P2 :

Resource A B C
work 10 4 6

Set Finish of P2 to True :


Process Finish
P0 True
P1 True
P2 True
P3 True
Safe Sequence < P0,P1,P2,P3>

Safe Sequence
 Safe Sequence: < P0,P1,P2,P3>
 Safe State : Yes

You might also like