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

Chapter-4 Bankker Algorithm Problems

The document outlines a series of steps to determine safe states in a system to avoid deadlock using the Banker's algorithm. It includes calculations of resource needs, allocations, and the available resources for multiple processes. The safe sequences identified for each scenario are P1->P3->P0->P2->P4 and P1->P3->P4->P0->P2, as well as P0->P2->P3->P4->P1.

Uploaded by

Ashfaq Hussain
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 views3 pages

Chapter-4 Bankker Algorithm Problems

The document outlines a series of steps to determine safe states in a system to avoid deadlock using the Banker's algorithm. It includes calculations of resource needs, allocations, and the available resources for multiple processes. The safe sequences identified for each scenario are P1->P3->P0->P2->P4 and P1->P3->P4->P0->P2, as well as P0->P2->P3->P4->P1.

Uploaded by

Ashfaq Hussain
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

Total instances of = A, B, C 7+3 2+3 5+2 = 10, 5, 7

Step-1: Need = Max – Allocation

7 5 3 0 1 0 7 4 3 P0

3 2 2 2 0 0 1 2 2 P1

9 0 2 - 3 0 2 = 6 0 0 P2

2 2 2 2 1 1 0 1 1 P3

4 3 3 0 0 2 4 3 1 P4

Step -2: Work = Available = (3, 3, 2) assume Finish(i) = (F ,F , F, F, F)

Step 3: Make the table

Note: Remember to Change Work values

Is the process where If so, Finish(i) = True


need <= work Work = Work + Allocation(i) P0, P1,P2,P3,P4
P1 (3, 3, 2)+ (2, 0, 0) = (5, 3, 2) F, T, F, F, F
P3 (5, 3, 2) + (2, 1, 1) = (7, 4, 3) F, T, F, T, F
P0 (7, 4, 3) + (0, 1, 0) = (7, 5, 3) T, T, F, T, F
P2 (7, 5, 3)+ (3, 0, 2) = (10, 5, 5) T, T, T, T, F
P1 (10, 5, 5)+ (0, 0, 2) = (10, 5, 7) T, T, T, T, T

So Safe state of the system is P1->P3->P0->P2->P4 to avoid deadlock.


Check for Total Instances = A, B, C 7, 10, 5

Step-1: Need = Max – Allocation

3 7 5 0 0 1 3 7 4 P0

2 3 2 0 2 0 2 1 2 P1

2 9 0 - 2 3 0 = 0 6 0 P2

2 2 2 1 2 1 1 0 1 P3

3 4 3 2 0 0 1 4 3 P4

Step -2: Work = Available = (2, 3, 3) assume Finish(i) = (F ,F , F, F, F)

Step 3: Make the table

Note: Remember to Change Work values

Is the process where If so, Finish(i) = True


need <= work Work = work +allocation(i) P0, P1,P2,P3,P4
P1 (2, 3, 3) +(0,2,0) = (2,5,3) F, T, F, F, F
P3 (2,5,3) + (1,2,1) = (3,7,4) F, T, F, T, F
P4 (3,7,4) +(2,0,0) = (5,7,4) F, T, F, T, T
P0 (5,7,4) + (0,0,1) = (5,7,5) T, T, F, T, T
P2 (5,7,5) + (2,3,0) = (7,10,5) T, T, T, T, T

So Safe state of the system is P1->P3->P4->P0->P2 to avoid deadlock.


Exercise Problem

Check for Total Instances = A, B, C 7+0, 2+0, 6+0 = 7, 2, 6

Step-1: Need = Max – Allocation

0 1 0 0 1 0 0 0 0 P0

4 0 2 2 0 0 2 0 2 P1

3 0 3 - 3 0 3 = 0 0 0 P2

3 1 1 2 1 1 1 0 0 P3

0 0 4 0 0 2 0 0 2 P4

Step -2: Work = available = (0, 0, 0) assume Finish(i) = (F ,F , F, F, F)

Step 3: Make the table

Note: Remember to Change Work values

Is the process where If so, Finish(i) = True


need <= work Work = work +allocation(i) P0, P1,P2,P3,P4
P0 (0, 0, 0) + (0,1, 0) = (0, 1, 0) T, F, F, F, F
P2 (0, 1, 0) + (3, 0, 3) = ( 3, 1, 3) T, F, T, F, F
P3 (3, 1, 3) + (2, 1, 1) = (5, 2, 4) T, F, T, T, F
P4 (5, 2, 4) + (0, 0, 2) = (5, 2, 6) T, F, T, T, T
P1 (5, 2 , 6) + (2, 0, 0) = (7, 2, 6) T, T, T, T, T

So Safe state of the system is P0->P2->P3->P4->P1 to avoid deadlock.

You might also like