Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
14 views7 pages

BC210200353 Assignment - 02 CS - 604

The document analyzes the current state of a system using the Banker's Algorithm based on available resources, allocations, and requests from five processes (P0 to P4). It calculates the Max and Need matrices, checks each process's ability to complete with current resources, and determines that the system is in a safe state with a safe sequence of P0, P1, P2, P3, and P4. The final conclusion is that all processes can finish, confirming the system's safety.

Uploaded by

Talha Sajid
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)
14 views7 pages

BC210200353 Assignment - 02 CS - 604

The document analyzes the current state of a system using the Banker's Algorithm based on available resources, allocations, and requests from five processes (P0 to P4). It calculates the Max and Need matrices, checks each process's ability to complete with current resources, and determines that the system is in a safe state with a safe sequence of P0, P1, P2, P3, and P4. The final conclusion is that all processes can finish, confirming the system's safety.

Uploaded by

Talha Sajid
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/ 7

OPERATING SYSTEM CS_604

ASSIGNEMENT_02
VU ID: BC210200353 NAME: TALHA SAJID
Analyze the current state of a system based on the following data, which includes:
The available system resources,
a)
The resources already allocated to each process,
b)
The new resource requests made by each of the five processes (P0, P1, P2, P3, and P4).
c)
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 Initially 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

Derived the Max Matrix


Max Matrix 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

Calculate the Need Matrix


Need Matrix 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

Present Available Resources Table


Proces Allocation Need Available
s
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, it can complete with the current work resources:
Process P0:
Need A B C
P0 0 0 1

Need0 ≤ Work is True (because 0 < 3 and 1 < 2)


So, P0 would be the first process for which we fulfilled its need
Update work by adding Allocation of P2:
Resource A B C
Work 3 3 2

Set finish of P0 to True:


Process Finish
P0 True

Safe Sequence <P0>


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, it can complete with the current work resources:
Process P1:
Need A B C
P1 2 0 2

Need1 ≤ Work is True


So, P1 would be the Second process for which we fulfilled its need
Update work by adding Allocation of P2:
Resource A B C
Work 5 3 2

Set finish of P1 to True:


Process Finish
P0 True
P1 True

Safe Sequence <P0, P1>


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, it can complete with the current work resources:
Process P2:
Need A B C
P2 0 0 0

Need2 ≤ Work is True


So, P2 would be the third 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>


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, it can complete with the current work resources:
Process P3:
Need A B C
P3 1 0 0

Need3 ≤ Work is True


So, P3 would be the fourth 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 P3 to True:


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

Present Available Resources Table

Process Allocation Need Available


A B C A B C A B C
P4 0 0 2 0 0 2 10 4 6

Check each process to see, it can complete with the current work resources:
Process P4:
Need A B C
P4 0 0 2

Need4 ≤ Work is True


So, P4 would be the fifth process for which we fulfilled its need
Update work by adding Allocation of P4:
Resource A B C
Work 10 4 8

Set finish of P4 to True:


Process Finish
P0 True
P1 True
P2 True
P3 True
P4 True

Safe Sequence <P0, P1, P2, P3, P4>

Since all the processes can finish, system is in a safe state.


Safe Sequence
 The safe sequence <P0, P1, P2, P3, P4>
 Safe State: Yes
 Safe Sequence: P0, P1, P2, P3, P4

You might also like