Posts

Showing posts from March, 2016

Bankers Algorithm in C

Image
Hey. Today in this post we will be dealing with Bankers Algorithm. Bankers algorithm is used in Operating systems to prevent deadlocks and it is a resource allocation algorithm. First of all let me explain what is a Bankers algorithm.

Bankers Algorithm

Consider there are 3 resources A, B and C. There are 6, 6, 6 instances of the resources availablerespectively. Consider 3 processes P0, P1 and P2. Consider the following matrix which shows the instances of the resources that are allocated to P0, P1 and P2.



And consider the following instances of A, B and C are still required by the processes to complete it's execution.



First let us consider P0. 3, 1, 1 instances of A, B and C are required for its completion. There are 6, 6, 6 instances available. So we can afford the required instances. After completion of the process P0 the available instances of A, B, C would become 7, 7, 7. Then the process P1 would be executed as 3, 4, 4 instances are available. The available resources would bec…