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

Banker's Algorithm Example

The document provides an example of applying the Banker's Algorithm to resolve resource allocation conflicts across 5 processes (P0-P4) competing for 3 resource types (A, B, C). It shows the initial allocation and available resources, and then walks through granting additional resources to processes while ensuring the system remains in a safe state without causing deadlocks. The example concludes by showing how all processes' needs are met through the sequenced allocation of resources from P1 to P3 to P4 to P2 and finally to P0.

Uploaded by

Saurav Semalti
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views

Banker's Algorithm Example

The document provides an example of applying the Banker's Algorithm to resolve resource allocation conflicts across 5 processes (P0-P4) competing for 3 resource types (A, B, C). It shows the initial allocation and available resources, and then walks through granting additional resources to processes while ensuring the system remains in a safe state without causing deadlocks. The example concludes by showing how all processes' needs are met through the sequenced allocation of resources from P1 to P3 to P4 to P2 and finally to P0.

Uploaded by

Saurav Semalti
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 17

Banker’s Algorithm

Koyel Datta Gupta


Example of Banker’s Algorithm
• 5 processes P0 through P4; 3 resource types A
(10 instances), B (5instances), and C (7 instances).
• Snapshot at time T0:
Allocation Max Available Need(Max-Allocation)
A B CA B C ABC ABC
P0 0 1 0 7 5 3 3 3 2* 743
P1 200322 122
P2 302902 600
P3 211 222 011
P4 002433 431
-------------
725
* 10 5 7 - 7 2 5 = 3 3 2
Example of Banker’s Algorithm (Contd..)

Allocation Max Need Available


ABC ABC ABC ABC
P0 010 753 743 3 3 2 2 1 0*
P1 322 322 122
P2 302 902 600
P3 211 222 011
P4 002 433 431
* 332–122=210
P1
Example of Banker’s Algorithm (Contd..)

• Allocation Max Need Available


ABC ABC ABC ABC
P0 010 753 743 2 1 0 5 3 2*
P1 322 322 122
P2 302 902 600
P3 211 222 011
P4 002 433 431
* (2 1 0+ 2 0 0+ 1 2 2)= 5 3 2
P1 -> P3
Example of Banker’s Algorithm (Contd..)

• Allocation Max Need Available


ABC ABC ABC ABC
P0 010 753 743 5 3 2 5 2 1*
P1 322 322 122
P2 302 902 600
P3 222 222 011
P4 002 433 431
* 5 3 2 – 0 1 1 =5 2 1
P1 -> P3
Example of Banker’s Algorithm (Contd..)

• Allocation Max Need Available


ABC ABC ABC ABC
P0 010 753 743 5 2 1 7 4 3*
P1 322 322 122
P2 302 902 600
P3 222 222 011
P4 002 433 431
* 5 2 1+222=743
P1 -> P3 -> P4
Example of Banker’s Algorithm (Contd..)

• Allocation Max Need Available


ABC ABC ABC ABC
P0 010 753 743 7 4 3 31
2*
P1 322 322 122
P2 302 902 600
P3 222 222 011
P4 433 433 431
* 7 4 3- 4 3 1=31 2
P1 -> P3 -> P4
Example of Banker’s Algorithm (Contd..)

• Allocation Max Need Available


ABC ABC ABC ABC
P0 010 753 743 3 1 2 74
5*
P1 322 322 122
P2 302 902 600
P3 222 222 011
P4 433 433 431
* 3 1 2+ 4 3 3= 7 4 5
P1 -> P3 -> P4 -> P2
Example of Banker’s Algorithm (Contd..)

• Allocation Max Need Available


ABC ABC ABC ABC
P0 010 753 743 7 4 5 14
5*
P1 322 322 122
P2 902 902 600
P3 222 222 011
P4 433 433 431
* 7 45- 6 0 0= 1 4 5
P1 -> P3 -> P4 -> P2
Example of Banker’s Algorithm (Contd..)

• Allocation Max Need Available


ABC ABC ABC ABC
P0 010 753 743 1 4 5 10 4 7*
P1 322 322 122
P2 902 902 600
P3 222 222 011
P4 433 433 431
* 1 4 5 + 9 0 2 = 10 4 7
P1 -> P3 -> P4 -> P2-> P0
Example of Banker’s Algorithm
• 4 processes P0 through P3; 4 resource types W (5 instances), X (8
instances), Y (6instances), and Z (7 instances).
• Snapshot at time T0:
Allocation Max Available Need(Max-Allocation)
WXYZ WXYZ WXYZ WXYZ
P0 010 2 4743 1 4 4 2* 4 641
P1 3200 3322 01 2 2
P2 1012 2812 1 8 00
P3 011 1 2326 2 2 1 5
------------
4425
*5 8 6 7- 4425 =1442
Example of Banker’s Algorithm

Allocation Max Available Need(Max-Allocation)


WXYZ WXYZ WXYZ WXYZ
P0 010 2 4743 1 4 4 2 1 3 2 0* 4 6 4 1
P1 3322 3322 01 2 2
P2 1012 2812 1 8 00
P3 011 1 2326 2 2 1 5

*1 4 4 2- 0 122 =1320

P1
Example of Banker’s Algorithm

Allocation Max Available Need(Max-Allocation)


WXYZ WXYZ WXYZ WXYZ
P0 010 2 4743 1 3 2 0 4 6 4 2* 4 6 4 1
P1 3322 3322 01 2 2
P2 1012 2812 1 8 00
P3 011 1 2326 2 2 1 5

*1 3 2 0 + 3 322 =4642

P1 -> P0
Example of Banker’s Algorithm

Allocation Max Available Need(Max-Allocation)


WXYZ WXYZ WXYZ WXYZ
P0 474 3 4743 4 6 4 2 0 0 0 1* 4 6 4 1
P1 3322 3322 01 2 2
P2 1012 2812 1 8 00
P3 011 1 2326 2 2 1 5

*4642-4642=0001

P1 -> P0
Example of Banker’s Algorithm

Allocation Max Available Need(Max-Allocation)


WXYZ WXYZ WXYZ WXYZ
P0 474 3 4743 0 0 0 1 4 7 4 4* 4 6 4 1
P1 3322 3322 01 2 2
P2 1012 2812 1 8 00
P3 011 1 2326 2 2 1 5

*0001+4743=4744

P1 -> P0 ?
W X

Y
P2

P3

Resource Allocation Graph (P2


and P3 )
P2 P3

Wait For Graph (P2


and P3 ) shows DEADLOCK

You might also like