Deadlock Avoidance (banker's Algorithm) | Operating System - M04 P05

Deadlock Avoidance (banker's Algorithm) | Operating System - M04 P05

This is a multipart blog article series, and in this series I am going to explain you the concepts of operating system. This article series is divided into multiple modules and this is the forth module which consists of 8 articles.

In this article we will discuss about banker’s algorithm which is a deadlock avoidance method.

Banker’s algorithm

  • We have to tell the system that what process are coming, which process will request for which resource, how many resource and for how much time.
  • All this information we have to give to the system before process arrives, then system will decide that which process is going to wait or execute and for how much time it will wait or execute.
  • It is also used for deadlock detection which means it can find that deadlock can occur in future or not.

Let’s see an example to get better understanding about banker’s algorithm.

Example: Find the safe sequence. We have resource A = 10, resource B = 5 and resource C = 7.

Safe sequence means that the sequence of execution process and allocation resources which will do not cause deadlock.

Process No.Allocatoin of AAllocatoin of BAllocatoin of CMax need of AMax need of BMax need of CCurrent availability of ACurrent availability of BCurrent availability of CRemaining need of ARemaining need of BRemaining need of C
P1010753332743
P2200322532122
P3302902743600
P4211422745211
P5002533755531
  • Current availability: (3,3,2)
  • With this current availability we can fulfill the request of P2
  • Current availability: (5,3,2)
  • With this current availability we can fulfill the request of P4
  • Current availability: (7,4,3)
  • With this current availability we can fulfill the request of P5
  • Current availability: (7,4,5)
  • With this current availability we can fulfill the request of P1
  • Current availability: (7,5,5)
  • With this current availability we can fulfill the request of P3
  • Current availability: (10,5,7) = Total resources.
  • Safe sequence: P2 -> P4 -> P5 -> P1 -> P3
  • No deadlock will occur so it is safe.
  • More than one safe sequence is possible.

So this was all about deadlock avoidance (banker’s algorithm). Hope you liked it and learned something new from it.

If you have any doubt, question, quires related to this topic or just want to share something with me, than please feel free to contact me.

📱 Contact Me

Twitter, LinkedIn, Telegram, Instagram,

📧 Write a mail

rahulmishra102000@gmail.com

GitHub, HackerRank