Last updated on:May 26th, 2018,

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;

ProcessTotal instances of Resource ATotal instances of Resource BTotal instances of Resource C
P0010
P1200
P2302
P3211
P4002

Table: Showing resources already processes occupies

 

[quads id=1]
ProcessTotal instances of Resource ATotal instances of Resource BTotal instances of Resource C
P0753
P1322
P2902
P3222
P4433

Table: Showing maximum resources required for complete execution.

 

ProcessTotal instances of Resource ATotal instances of Resource BTotal instances of Resource C
P0743
P1122
P2600
P3011
P4431

Table: Showing needed resources to each process for execution.

Needed resources = maximum resources – allocated resources

 ProcessTotal instances of Resource ATotal instances of Resource BTotal instances of Resource C
P0332
P1532
P2532
P3743
P4745
P0755
P21057

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

 

0Shares

Leave a Reply

Your email address will not be published.