Deadlock Avoidance: Bankers(Resource Request Algorithm) with example |Operating System

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
this snapshot has given maximum and allocation and available we have available resources we have and you have to answer these question first of all to find out media metrics second one is you have to find out a system in safe state and if yes then you have to find out safe sequence next is see these two things are new if requests from any process requests from p1 arrives for these resources can this request be granted immediately and next as if request from p4 arrives for this resources then can this request be granted immediately we will check out this thing also right so first of all find out need metrics need metrics how to find out need metrics that maximum for that process - a location of that process because each process has already told the operating system that I will need maximum B's number of resources and these number of resources are already allocated so obviously need would be maximum - allocation so need matrix of this p0 would be maximum 4 minus 2 is 2 here we will write - 1 - 0 1 2 minus 1 is 1 so this is the min need matrix fine now next question is you have to find out a system in safe state what do you mean by safe state if the system is able to execute all the processes without going to unsafe state then you can say system is in safe state and in which sequence the system will execute these processes that sequence will know will be known as safe sequence fine now find out safe sequence currently available resources on this one check out the which need you can fulfill which process need you can fulfill with this available resources will start from P node it needs 2 instances of a we have three it is two instances of B we have three it need one instance of C we have two in Tier one instance of D we have one yes we can fulfill this need fine now you will write P node if you want you can take it out further for the for p1 also it is 2 instances we have 3 it need one instance of B we have three it's three instances of C but we have only two so you cannot fulfill this need same way this one see it needs three instances of D but we have only one you cannot fulfill this one so same with next one it me it needs two instances of D but we have only one we cannot fulfill this one same with this one it needs three instances of day and three of C but we have two and one so we cannot fulfill this one the system can only fulfill requests of P note second thing what we we do just add the allocation of that process to this available because as soon as this process will get all its required the sources then after some amount of time it completes its execution and then it will release all its allocated resources so what you will do in available resources just check out the location of P note and add to this one three plus two is five here three here to here we have two now this P node work completed now with the help of this available resources now which process need you can fulfill check out for this one - we have five one we have three it needs three instances but we have only two so you cannot fulfill this need what about this one it did three instances obey we have two you cannot fulfill this one what about this one yes we can fulfill this one it needs zero five it needs one we have three it needs one we have two it needs to we have two so you can fulfill this request so next is p3 fine now next thing is just check out that location of this p3 and add in the available resources 5 plus 1 is 6 3 plus 3 is 6 2 plus 1 is 3 2 plus 2 is 4 now p3 also got completed now remaining is 3 check out with the help of this resources can you fulfill request of any of these three we will check out with p4 it needs 2 we have sex it needs to we have 6 it needs 3 of C we have three it needs 3 we have 4 yes you can fulfill this need you can take it out for this also fine C definite also we can fulfill with this available resources so either you can execute P notary that you can execute P 1 so safe sequence can be more than 1 it's up to you how to solve this question exists now before got completed and it will release its resources so we will add its allocated resources to available sources now 6 plus 1 is 7 6 plus 4 is 10 3 plus 3 is 6 4 plus 2 is 6 right now next is we have these two resources so obviously I guess with these resources you can fulfill this need also end this need also fine so either you can take p1e then you can get or you can take people suppose I am taking p1 now add the located resources of p1 to this available resources 7 plus this one is 11 right now finally we have p2 now check out a location of this one and add to this one 10 + 12 - n here 10 n so you are able to find out a safe sequence it means system is in safe state so answer would be yes and what a safe sequence so this is the safe sequence it's a Sig safe sequence can be more than one and so I go to the safe sequence right now see you can check it out you can tell me your answer how available the sources are this one and after executing all the processes you go to these number of resources it means total number of resources are this one fine now how to find out total number of resources now see first of all at first available resources were this one and after allocating these resources these were available resources so just add the allocated resources plus these available resources and you should get this number then you can say that you are going right so just add these resources these allocation resources 2 + 3 5 7 9 see now this and this number is same so you can tell your answer like this also now now we will discuss how to solve this question so now the third question is see if any requests from p1 arrives for this number of resources then can this request be granted immediately right see when a request comes then the system does not grant that request immediately in deadlock avoidance case but why because deadlock avoidance phase is futuristic approach so system will you know at that time will not grant that request immediately system will check if if I request if I grant this request at this time then will I be in safe state in future or will I get any deadlock in future so if that system get any deadlock may be immediately because of that request or may be in future then that request would not be granted at that time although the resources are available but that in that case also system will not grant that request why so it is it analyzed that it has some data and it analyzed that data and it it comes to the point that because of that granting of this request at this time I can get deadlock in future so that is why that system will not that the request will not be granted now how this would be checked this would be checked using the source request algorithm and then finally apply the safety algorithm or you can say bankers algorithm so now check p1 is requesting for resources 1 1 0 0 and we have this snapshot need of this matrix now so I hope you all know that that p1 or any process cannot request more resources then its need matrix because with resources each processes has initially told the system that we will need maximum these kind of resources and at this point of time already allocated resources are this one so obviously that process the need matrix will calculate and that process can now request this these number of resources at mix so if this request is exceeding from this need matrix then the system will raise an error that that process has exceeding it claim fine and second thing is we will check this request we have this number of available resources or not so we will check this request should be less than or greater less than or equal to available resources fine now if this is true now say this request is p1 is requesting one month zero zero so this the need matrix of women is two one three one so obviously this one is less than two and one is less than 1 is less than or equal to one so first condition is true now we will check do we have the available resources or not to fulfill this request so check out our available resources one instance at feed we have three one is ten set need we have three instances of way yes we have these kind of resources but it doesn't need that system will grant this request immediately no system third step is system will pretend not actually grant that request but system will pretend as if it has granted this request fine and then it will check it will apply bankers and go to the mode it will apply that safety algorithm and check in future if it is able to find any safe sequence then we can say that that's then the system will grant that request if the system will go in and save state because of this request then it will not grant this request fine now see in our system at this point system are pretending that it has granted this request now if system grants this request then what will happen obviously the need matrix of this p1 will be changed need matrix would be this need matrix - this one fine because p1 has requested this one and system has allocated this system is pretending that it has granted this request so need matrix movie need matrix - this 1 2 1 3 1 so 2 & 3 1 - 1 1 0 0 now second thing what would be updated is this available matrix because system has system is has granted this request so obviously the this 1 1 0 0 this request would be detected from available resources and third thing is already allocated resources are three one to one and again this number of resources would be allocated to this matrix then they locate a lock a location of this p1 would become this allocation plus one one zero zero so after updating these three changes then this this state of the system will be modified to something like this see everything is same only we have updated three things the location of P 1 3 1 2 1 plus this 1 3 plus 1 is 4 1 plus 1 is 2 + 2 1 next we will do we will update this available we will - these number of resources from this available so this would be available third thing what you will do you will - this resources this request from need matrix so this would be something like this and all thing would be see now system system would apply the safety algorithm and system will check villain will I be able to execute all these processes safely and if yes then says then system will grant this request now system is pretending system is checking for its future so now at this case now at this snapshot apply that same algorithm that bankers algorithm how you'll apply that algorithm find out safe sequence now how to find out safe sequence see with the help of these available resources now not check can you fulfill request of any any process check it out this P not requires - we have two instances - we have two instances one we have two instances and one we have one instance so we can fulfill this request so see we will execute P one first fine you can check it out another also and if you'll find if you a system is able to complete any other process also then you can write down that you can start your safe sequence with that process also it is fine now P 1 has been executed now what the next step is what in banker's algorithm we will add the allocated resources of this this process to available resources because this P P 0 now what completed and it will release all its allocated resources two plus two is four to two and two now find out now next is p1 now check out can you fulfill this request know why so because it requires three instances of C but we have only two so you cannot fulfill this request at this time now check out this one see it it it requires three instances of this D but we have only two so we cannot fulfill this request check out for this one zero we have four it requires 1 we have 2 1 we have 2 2 we have 2 guests you can fulfill this request so now p3 now what you'll add in available resources allocated resources of this p3 4 plus 1 is 5 3 plus 2 is 5 2 plus 1 is 3 2 plus 2 is 4 now this work completed now find out next next is p4 can you fulfill this request yes we can fulfill 2 it is less than 5 it requires 2 we have 5 it requires 3 instances we have 3 it requires 3 instances we have 4 so you can fulfill this request also now p4 now add a location met a location the sources of this p4 in this available resources 5 plus 1 is 6 5 plus 4 9 3 plus 3 is 6 4 plus 2 is 6 now p4 got completed now next remaining is p1 and p2 so obviously with this help of this available resources you can fulfill this request also and this also so you can take either p1 or p2 I'm get retaking p1 so after completing p1 we will add the allocation resources of p1 to available resources now this allocation resources not go for this one because you have updated this state to the state now 10 11 8 7 now p1 completed now next is p2 now add a located resources of p2 2 L 2 L 8 and and now after completing all the say this is safe sequence now system is able to get safe sequence now system can grant this request or you can say system will grant this request now taking this case after checking the safe sequence Y if system is able to get safe sequence then system will grant this request now you can say yes this request can this request be granted yes this request can be immediately granted fine because after granting this request system is able to find safe sequence system will not going unsafe state now check out for this one if the SEC West comes then can request this request to be immediately granted same method you'll apply to this also fine and system will pretend first of all system will pretend that it has granted this request now what would be the change in this case in this snapshot CP for the NIDA matrix of p4 would be changed available would be changed and a location of this p4 will be changed now the updated state is from this to this one after pretending that this is this request has been granted what should be changed in this state available would be changed this will will do - of these resources from available resources fine so available would do have three three zero and one next thing is need a matrix of this p4 would be changed need matrix is need of this p4 is this one and this request p4 has requested these resources and these resources has been given to p4 so we will - these resources to this one so need matrix would be 2 - 3 - 2 is 1 and 3 again already allocated resources at this one again and located resources have this one so we will add this and this and this will become 1 4 5 and 2 now system is checking system is at applying safety algorithm in system and checking for the safe state of this one if you are able to find out the safe sequence then system will grant this request now find out safe sequence apply that safety algorithm now with the help of these available resources check out which need you can fulfill for this one it requires two instances we have three it requires two instances of BB have three it requires one instance of C but we have only zero so you cannot fulfill this need same with this one so just check out for C I guess because available resources of available instances of C is only zero fine it requires three instances of C but we have zero kind fulfill it acquire one instance which I have zero can't fulfill it require one instance of C cannot fulfill it require one instance of C I have zero cannot fulfill so system is not able to fulfill any process need now obviously the system will go in and save State fine and F system find out that if I grant this request I will go in unsafe State then system will not grant that request so system will say no to this request so answer would be no this this request cannot be granted immediately see all the resources are available C resources are available so system can grant this request but resources are available but in future because of this request because of granting this request immediately system may get stuck this term may be deadlocked so system will not grant this request so this is how system will avoid deadlock so this is a resource request algorithm whatever we have discussed I have written those in two steps C first step is if request request of a particular process is less than if want to need then then what we will do then what we will do again we will check request with this available resource if request is less than available then we'll go with step through step three is what system will pretend that this that request has been granted and this state would be modified to another state as we have discussed so system pretend as if request has been granted by modifying the state as follows now state would be followed all what need of that process has been changed available would be changed and a location for that process would be changed so available would be available - request of that is a location of that process see a location III means particular process so a location of that process becomes a location plus request and need of that process need of that process becomes need of that process - request of that process see the meaning of this the symbol is available is equal to available - request I hope you know this thing fine and after modifying this state if if say this is not it right now after modifying this request F modified resource a location state is safe see if you are able to the system is able to find out safe sequence then then since then request will be granted otherwise otherwise say no to the urgent request and that previous or you can say old a location resource state would be restored so the D step we have already discussed when we were discussing the answer of when we were finding the answer of these questions so I hope no need to explain further these steps you know you got this resource request algorithm in next video we will discuss how to detect deadlock in the system and how to recover deadlock detection and recovery basically so till then bye-bye techniques
Info
Channel: Jenny's lectures CS/IT NET&JRF
Views: 57,722
Rating: 4.9178886 out of 5
Keywords: deadlock, what is deadlock, os, operating system, os notes, deadlock avoidance, bankers algorithm, resource request algorithm, how to find safe sequence, need matrix, ugc net computer science study material, best computer science youtube channel, technology, engineering colleges, technical, jayanti khatri lamba, jennys lectures, NTA UGC NET syllabus june 2019, cse, IT, preparation, operation, schedule, banker's algorithm, algorithms, data structures, deadlock in os
Id: Or40J_f2RHo
Channel Id: undefined
Length: 21min 18sec (1278 seconds)
Published: Fri May 10 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.