Banker’s algorithm in operating system (OS)

Banker’s algorithm:

Banker’s algorithm is an algorithm to avoid deadlock and to allocate resources to the processes safely.

Let’s discuss with an example;

Process Total instances of Resource A Total instances of Resource B Total instances of Resource C
P0 0 1 0
P1 2 0 0
P2 3 0 2
P3 2 1 1
P4 0 0 2

Table: Showing resources already processes occupies

 

[quads id=1]
Process Total instances of Resource A Total instances of Resource B Total instances of Resource C
P0 7 5 3
P1 3 2 2
P2 9 0 2
P3 2 2 2
P4 4 3 3

Table: Showing maximum resources required for complete execution.

 

Process Total instances of Resource A Total instances of Resource B Total instances of Resource C
P0 7 4 3
P1 1 2 2
P2 6 0 0
P3 0 1 1
P4 4 3 1

Table: Showing needed resources to each process for execution.

Needed resources = maximum resources – allocated resources

 Process Total instances of Resource A Total instances of Resource B Total instances of Resource C
P0 3 3 2
P1 5 3 2
P2 5 3 2
P3 7 4 3
P4 7 4 5
P0 7 5 5
P2 10 5 7

Table: Showing available free resources for each process.

Now compare available free resources of each process with its needed resources. The needed matrix should less than/equal as compared to the available matrix for process execution.

 

[quads id=2]

First iteration:

P0=finish[p0]=False              can’t execute because if we assign free resources 

to P0, and we add the free resources of P0 with

needed resources of P0, its still does not fulfill the

requirement of maximum resources needed to P0 for

its execution.

P1=FINISH[P1]=TRUE         can execute

P2=FINISH[P2]=False          can’t execute

P3=FINSH[P3]=TRUE          can execute

P4=FINISH[P4]=TRUE         can execute

2nd iteration:

P0=FINISH[P0]=TRUE          can execute

P2=FINISH[P2]=TRUE         can execute

 

Fazal Rehman Shamil
Welcome to all friends. The reason for our success is only your love for T4Tutorials. Our team is always available to answer your queries regarding any kind of confusions or discussion regarding your study and career matters. For discussion with us please join our facebook group "T4Tutorials.com". The link of the group is mentioned below. Thanks and love to all for connecting with us. We are nothing without you. Love you all.....
https://web.facebook.com/groups/2066136233601097/

Leave a Reply