 assistant professor at doublet is solapur. Now in this study lecture we are going to discuss on the bankers algorithm. Friends at this end of video you should be able to describe what is a bankers algorithm and we should be able to implement to find the safe sequence of execution of process. Just see what is bankers algorithm means here. Friends the name is coming from a very familiar case here because whenever you go for loan in the bank the bank does not give loan directed to you but he will first check whether how much cash is available in the bank okay and based on some logic there they are going to disperse the loan to you. So friends similarly in my operating system I use the same concept here because we know here friends when process comes for execution he demands some resources from operating system. So this operating system is allocating some resources to process when that comes in the existence there but that does not mean that he get all the resources available from this OS. So it is possible that that process may not be getting executed even though he possess some resources with him okay. So friend I will say that the bankers algorithm is that kind of solution which is able to provide me the safe sequence of execution of processes in the system there. So that every system can get the required resources and we can avoid deadlocks there. Then this one more thing is to be understood here. Friend whenever you are finding safe sequence of execution in that system there I can say that there is no any case of deadlock is available. Then this algorithm also helps to share resources successfully between all the processes and still we are going to execute all these processes successfully. Now friend I will just go with the simple concept here. The bankers algorithm is going to decide as I said the safe sequence of process execution in the constraint environment of system here because you are getting limited resources in the system here okay. So it is one of the very important criteria that you are going to have constraint environment for the process execution there. Now the different parameters we use in this bankers algorithm. So friend normally the maximum number of resources required are normally defined by the process here. Then we also are knowing here number of resources available currently in the operating system here. Moreover we also are knowing some data regarding how many resources allocated by the operating system to the given process here. Now actually from these two parameters I can always find one new terminal called a need matrix here. What is that we will discuss in next slide. And from this bankers algorithm we are going to find out the safe sequence of execution. Friend I will just try to implement my concept here with this example. So example is showing you the two different columns here that is allocation and the max column there. So actually in my chart I am showing three processes that is p1, p2, p3 here. And this a, b, c, r resources they require to execute completely I can say. So presently friend when p1 comes in the existence this OS has allocated some resources to the p1 there. That is this OS has given one instance of a, two instance of b and one instance of c. Similarly for p2, 2, 0, 1 and for p3 it is 2, 2, 1. But friend again the next column this one more data is given here because to execute completely p1 requires some more resources there. So that column shows you maximum number of resources we expect from the OS there. So currently this p1 requires 2 instances, 2 instances and 4 c instances. Then p2 require 2 instances, 1 b instance and 3 c instances. So this is the maximum resources we require to execute that process completely. But from the chart you know that currently we do not possess all the resources with me so I am not able to carry out my execution. The example says that one more thing the maximum resources of a, b, c are equal to 5. And moreover currently friends we get some resources are left here with this OS and they are also mentioned here. Presently with this OS I am having 0 instance of a, 1 of b and 2 of 3 or 2 of c instance I can say. So these are resources available with the operating system. So friend when you implement this bankers algorithm we have to follow some steps here. So in the step 1 first I will try to find out here the need matrix here. That is how many resources we still require to execute that process p1, p2 and p3. So it is very simple that is need is equal to maximum requirement minus allocated resources there. That is max instances minus allocated instances. So just I am attending one more column there. So and these are made according to the difference here. So p1 require one instance of a, 0 instance of b and 3 instances of c for complete execution there. Similarly p2 requires 0 of a, then 1 of b and he required 2 instances of c. Similarly p3 requires a equal to 1, b2 and c, 0. Now that is our job to allocate or make resources available to the system there. Friend the example says that currently we get some resources are available to with me here. So I am just adding one more column now such as available resources there. The example says that currently I got 0 instance of a is available with me. I can have 1 instance of b and I am having 2 instances of c. So I can use that resources additionally so that we can execute some process here. So I am just adding one more column at the end that shows me the process executed. So friend I can not check here whether with available resources can execute any process in the chart or not. So friend I can say that if you see closely the p2 require now 0 instance of a, 1 instance of b and 2 of c. And presently I got that resource are available with me. So I can say that with these resources available I am able to execute the process p2. So I can execute process p2 there. Now when I execute this process p2, this p2 returns all resources back to this operating system. So that I will add these resources now with available and those now become balanced resources with the OS there. And so I am just adding these column here. So under this a column I got 0 plus 2 that comes 2, then I got 1 instance of b still remaining here and the process p2 returns 1 c resource here so that total c become 3. Now again with this resource available again check friend that which process we can execute here. So friend you see that the process p1 requires how many here? It requires 103. It is available with me here and still we require for p3 I require 120 here. So with this resource available I cannot execute process p3 here because p3 requires 2 instance of b which is not with me. So that I will go with the process p1 there. Now when p1 get executed he returns all resources back to this OS here. So this resource become 3, 3 is 4 and we know here with this resource available I can execute process with this successfully here. So I am going to execute that p3 and after this p3 execution these 3 p3 also returns all resources back to the system here. So ultimately the final resource available becomes 5, 5, 5 which is mentioned in the example there. So friends in this way just we operate this bankers algorithm which is very interesting here. Now just make some impressions on this algorithm. Now from the given example I can say that the same sequence of execution is process p2 then p1 and then p3. Now friend I can make one simple statement here. If you get a safe sequence of execution I can say that there will not be any case of deadlock. But friend whenever you do not get any safe sequence of execution which mean that the resource available are not able to execute any process here at that time it is a case of deadlock. So you can make a statement that when you get no safe sequence in the system deadlock bound to occur. So friend this is something about this bankers algorithm. I hope that you understand that example and you able to implement that example or that concept here. For the big example also I hope this today is helping you to understand the basic concept. Thank you friends for watching my video. Thanks very much.