Sample output of the Banker’s Algorithm:
– Enter claim graph
– Request resource
– Release resource
– Determine safe sequence
– Quit program
Enter selection: 1
Enter number of resources: 3
Enter number of units for resources (r0 to r2): 1057
Enter number of processes: 5
Enter maximum number of units process p0 will claim from each resource (r0 to r2): 753
Enter maximum number of units process p1 will claim from each resource (r0 to r2): 322
Enter maximum number of units process p2 will claim from each resource (r0 to r2): 902
Enter maximum number of units process p3 will claim from each resource (r0 to r2): 222
Enter maximum number of units process p4 will claim from each resource (r0 to r2): 433
Enter number of units of each resource (r0 to r2) currently allocated to process p0: 0 1 0
Enter number of units of each resource (r0 to r2) currently allocated to process p1: 2 0 0
Enter number of units of each resource (r0 to r2) currently allocated to process p2: 2 0 2
Enter number of units of each resource (r0 to r2) currently allocated to process p3: 21 1
Enter number of units of each resource (r0 to r2) currently allocated to process p4: 0 1 2
Available:
r0 r1 r2
3 3 2
Allocated:
r0 r1 r2
p0 0 1 0
p1 2 0 0
p2 3 0 2
p3 2 1 1
p4 0 0 2
Need:
r0 r1 r2
p0 7 4 3
p1 1 2 2
p2 6 0 0
p3 0 1 1
p4 4 3 1
Banker’s Algorithm:
– Enter claim graph
– Request resource
– Release resource
– Determine safe sequence
– Quit program
Enter selection: 4
Comparing: 743=332 : Process p0 cannot be sequenced
Comparing: 122=332 : Process p1 can be sequenced
Comparing: 60=532 : Process p2 cannot be sequenced
Comparing: 011=532 : Process p3 can be sequenced
Comparing: 431=743 : Process p4 can be sequenced
Comparing: 743=745 : Process p0 can be sequenced
Comparing: 600=755 : Process p2 can be sequenced
Safe sequence of processes: p1 p3 p4 p0 p2
Banker’s Algorithm:
– Enter claim graph
– Request resource
– Release resource
– Determine safe sequence
– Quit program
Enter selection: 2
Enter requesting process: p2
Enter requested resource: r0
Enter number of units process p2 is requesting from resource r0: 1
Enter selection: 3
Enter releasing process: p4
Enter released resource: r1
Enter number of units process p4 is releasing from resource r1: 1
Resources:
r0 10 5 3
r1 0 4 1
r2 2 2 7
Available:
r0 r1 r2
0 4 2
Max Claim:
r0 r1 r2
p0 7 5 3
p1 3 2 2
p2 9 0 2
p3 2 2 2
p4 4 3 3
Allocated:
r0 r1 r2
p0 0 1 0
p1 2 0 0
p2 2 0 2
p3 2 1 1
p4 0 1 2
Need:
r0 r1 r2
p0 7 4 3
p1 1 2 2
p2 7 0 0
p3 0 1 1
p4 4 2 1
Enter selection: 4
Comparing: 743=332 : Process p0 cannot be sequenced
Comparing: 122=332 : Process p1 can be sequenced
Comparing: 60=532 : Process p2 cannot be sequenced
Comparing: 011=532 : Process p3 can be sequenced
Comparing: 431=743 : Process p4 can be sequenced
Comparing: 743=745 : Process p0 can be sequenced
Comparing: 600=75 : Process p2 can be sequenced
Safe sequence of processes: p1 p3 p4 p0 p2
Banker’s Algorithm:
– Enter claim graph
– Request resource
– Release resource
– Determine safe sequence
– Quit program
Enter selection: 5
Quitting program…