L-4.4: Deadlock Handling Methods and Deadlock Prevention | Operating System

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
various methods to handle the deadlock situation basically there are four important methods which are used to handle the deadlock the methods are deadlock ignorance deadlock prevention deadlock avoidance and deadlock detection and recovery the first method is deadlock ignorance which is also known as ostrich method now if we when we have here the method deadlock ignore as the method says just ignore the deadlock so isn't it funny like when the deadlock situation is occurring we are simply ignoring the deadlock but yes our majority of the operating system like your Windows and Linux both use this strategy that is deadlock economists and it is used widely so what is in there in the deadlock ignorance means when the dialogue occurs in the system simply ignore it and this is phased by near about all of the users they face in their laptops the problem is what your system will get halt when the system will get hanged and what we do we simply power off and we restart the system so that is what the meaning of the deadlock ignores the funda behind it is why we are not creating some algorithms to remove the dead look at all the funda is key deadlock occurs very rare the programmer things the deadlock occur very rare like once in a five years or once in a 10 years so why we write a full-fledged code to remove the deadlock situation which will affect the performance means like whatever the operating system we use whatever the operating system like let us say windows operating system so Windows operating system already has a lot of code code in this like Windows operating system just like in the normal operating system it does memory management resources resource manager lot of things operating system does other than this if we increase one more related to handling the deadlock removing the deadlock the performance will be affected means performance of the system will get affected over there so we just want the speed we want the speed to speed just to have more and more speed what we do we are not writing the code to remove the deadlock in the situation so what we are doing what the programmers are doing they are not writing any patch they are not writing any code to remove the deadlock why because they think it occurs rare so just for the rare occurrence they are not writing any code for removing of the deadlock so what is the advantage we are getting in this means the operating system whatever the major task of the operating system the operating system is doing that task only means we are not increasing the functionality of the operating system PS our operating system is also capable to remove the deadlock if we try to do this means if we try to increase the capability of the operating system definitely it will affect the performance speed means if we are trying to provide more and more functionalities the speed will be getting less but nowadays we are totally into the speed we are not talking about the correctness means ok no problem one or two problems occur but these problem occurs very rare so just for the rare occurrence of this problem the simple method is ignore the deadlock so what we do we just restart the systems so this is the meaning of the deadlock ignorance and this is the widely used technique and from where we actually use this method that is the ostrich ostrich is a bird what it does whenever there is a sand storm it just put his neck into the sand means it just simply say there is no sand storm so means it is trying to ignore the sand storm so same what we are doing in the deadlock ignorance whenever there is a deadlock situation occurs we are simply ignoring that so that is the simple concept of the denim and why while we are ignoring because we won't we don't want to affect the performance performance or we can say speed so there is a kind of trade-off trade-off trade-off between one set of programmers which says he no I am NOT writing any code for the deadlock if we write the code for the deadlock the system will get more and more functionalities so just for getting more and more functionalities the speed the performance will degrade the performance will be getting degraded but one set of person says you know we should write the code for that but as if we talk about the users normally users we are all concerned with more with the speed we want speed in our laptops in our systems but correctness yes we want the correctness also but that kind of correctness or that kind of situation which occurs daily for that we need the correctness but deadlock situation doesn't matter daily we our system is already capable of like memories enough we are having the CP is enough the capabilities are enough but still if the deadlock occurs which is rare which is very rare so no problem we are simply ignoring that so just because of the rare occurrence we are simply ignoring the deadlock situation this is a simple meaning of the deadlock ignorance and Windows Linux operating system they use the deadlock ignorance method the second method is deadlock prevention the concept of demo prevention is like normal the very important phrase is key prevention is better than cure the method is key the time when the deadlock occurs we are trying to find the solution better is key before the deadlock occur we try to find some solutions so what are the solutions we can do or what are the Prevention's we can do the main progressions are whatever the four conditions like four conditions and necessary conditions the necessary conditions are just writing mutual exclusion no preemption hold and wait and circular bit as we know these four conditions are mandatory conditions or necessary conditions to have deadlock in the system so what deadlock prevention says either try to remove all the four necessary conditions from the system or at least try to remove or discard one of the one of them condition means we try to we try to simply false one of the situation means if all the situations are true then there is a deadlock but if one of the situation means one of the condition get false the deadlock will be prevented so this is the meaning of that under prevention any of the for any of the four or all four we try to make it false if any of the situation get false the deadlock will be prevented this is the simple concept of the deadlock prevention like mutual exclusion what is the mutual exclusion simple method is keep whatever the resources we are using they should be non sharable they should be non shareable means they should not be used at the same time by multiple processes if it happens deadlock will not occur so what we do in the mutual exclusion every process yet every resource will be used by one process at a time so if we false this situation if we try to false this condition that headlock will be removed means if I say let's say CPU if I make my system like that keep no problem CPU can be shared by more than two to three processes then why what is the need of the deadlock we'll be removed in this situation but there is a problem in the mutual exclusion also means not all the resources can be made as in non shareable or shareable means let's say printer printer if I want to remove the mutual exclusion what we have to do we have to make all the resources shareable so that no prevention made the first condition is the mutual exclusion we try to make it false false means how we can make the mutual exclusion false we can simply say all the resources can be shareable means at a time multiple resources can share the resource if it is possible deadlock will be prevented but how it can be possible for printer how it can be possible for tape drive because some of the resources are made like that which cannot be made as a non sharable which cannot be made as a shareable they are non shareable means printer cannot be made as a sharable it is always an honorable so in this situation this condition will get we it is very hard to make it false although we can make it false for some of the resource like CPU memory and all but there are some of the resources which cannot be made as a shareable unquestionable benaiah in each a sector like printer tape drives so when it cannot be a sharable how we can remove the mutual exclusion mutual exclusion cannot be removed so if it is cannot be removed the deadlock cannot be prevented fine so this is the main point in the mutual exclusion but yes if all the resources can be shareable the deadlock will never occur so there will be prevention in the deadlock second no preemption no preemption means if a process is going on another process is going on I will try to preempt one of the process so when the process will be preempted whatever there is it is holding it will be given to another process let's say I'm just making the diagram we have already seen this diagram many times let's say there is one resource of carbon which is taken by P 1 and R 2 resource is taken by P 2 and P 2 is requesting for this is a simple with representation R 1 is taken by P even requesting for R 2 R 2 is taken by P 2 requesting for now in this method if I try to make let's say P even get preempted I simply say keep even you just preempt if the people got preempted means it will stop working it will be sent back to the ready ready state mate will be given so from the running it will be sent to the ready state so when it's sent to the ready state whatever it is holding ahold Kiev even eight people is holding Irvin this R 1 will be taken back means I will simply take back our one from P 1 because P 1 is not existing and we can simply say just remove the even if it is preempted because in the preemption we are trying to switch means P 1 will be switch it will be given back to the ready state and Peter will start running so in this situation P 2 already has our 2 P 2 needs only R 1 and R 1 is free so if the process is free if the resource is free give it simply so I will give this resource to P 2 now P 2 can successfully execute so what we are trying to do we are trying to make the preemption these resources or sorry processes can be preempted so how we can do it by using the time quantum by using the time quantum kind of what time stamped kind of we use the time stamp method or time quantum method means a process can run for this particular time stream five-second ten seconds after that particular time say time it will be preempted so when it got preempted the resources will be taken back and it will be given to some other process and that process will use them and it will be removed so when it is gone means there is no deadlock so we are trying to prevent by making the no preemption to all the preemption and in the first we are trying to make the deadlock prevention from mutual exclusion to no mutual exclusion although it is not easy to make it but yes this is the method so in the second preemption no preemption so we are trying to make it preemption means preemption is allowed if the preemption is allowed deadlock will be prevented third hold and bit again we are trying to negate it we are trying to Falls it means there should be no hold and wait how to make it no hold and wait what we are trying to do if the process comes processes I need three resource what we will do before the process gets start I will give all the resources to that particular process means before the process gets started whatever it is demanding I will simply provide all the resources to that particular process although it is practically very impossible to do it because I cannot give that resources simply to of unprocess other process will be totally waiting for any of the resources but still this is a kind of method so we are just following this method means rather than a process holding some resource waiting some other resource what we are saying you just hold all the process all the resources you need we will simply give all the resources what it needs before it gets started so when it get all the resources after sometime it will get executed when it get execute means there is no deadlock because resources will be free it be given to some other process so what we are trying to do hold and wait keep agile we are trying to wait trying to do no hold element now the fourth one is circular made for deadlock there must be a circular wait but to remove the circular wait means if we want the deadlock should be prevented there should not be the circular it means we are trying to remove the condition of circular wait from the system so how we are trying to remove it the simple method is let's say I'm having lots of resources in my system so this method says see how we can remove the circular wait condition just give the numbering just order all the resources means if we want there should be there should be no circular wait in my system what we are trying to do we are giving the numbering like let's say I'm having printer scanner CPU let's say register various resources we have what we are trying to give we are trying to give the numbering simple just give them numbering to all the resources and the condition is keep whenever a process is requesting for a resource it will request in the increasing order means if a process p1 comes t1 says let me make the diagram let's see if p1 comes even say is I need one means printer means I need one printer so printer means one let us say a resource one so it has taken printer that is the source number one numbering one that is printer now it can requests for two three four means in the increasing order let's say now it was CPU so it can request for CPU yes it can request for resource number three that is CP what is the resource number three CP what is the resource number one let's say Brendan it's coming let's say CPU LX a printer now if the other process comes let's say now P two comes P 2 comes P to a process the main line is what a process can request in increasing order this is a simple meal a process can request only in the increasing order means if the order is increasing then only can it can request means if P 2 comes P 2 says I need CPU means I need the resource number 3 no problem I can give I can give the resource number 3 to P 2 now P to say is I need resources number 2 or I needed resource number 1 means a number which is less than the it already have the number it which is less no a process cannot request for the number less than the previous request means now this P 2 says I need the number one resource no it cannot request this request cannot be made if this request cannot be made we can simply say there is no circular bit because this line is there this is there this is there but this line cannot be made this line cannot be made but can we say TP 2 can request for resource for yes P 2 can request for the resource number which is greater the previous request because p2 has already Requested for the resource number 3 that is CPU so I just simply gave it now p2 says I need the resource number 1 so 1 is less than the 3 no the previous request must be greater than the current request so yes previously request is 3 now the p2 says I need resource number 1 no the request number cannot be less so a process the simple meaning is a process can request for a resource in the increasing order only means if a process is I need the resource number 3 no problem it can have 3 next time it can request for 4 5 6 note the lower one by doing this we will simply removing the circular wait conditions so when the circular wait condition will be removed we can simply say deadlock will be prevented this is a simple mean next is the deadlock avoidance what is the concept of deadlock avoidance means we are trying to give the resources to the process and whenever we give the resource to the process we will check given it is a safe situation or not means when we give the resources to a particular process we check whether deadlock can be occur or nor dead low can be avoided or not for every we for every resource allocation we check the safe or unsafe situation this is done by the bankers algorithm disastrous algorithm is also known as this bankers algorithm is given by that each gastrous that is the scientist so bankers algorithm resolved this problem that is that deadlock avoidance so for getting more details of banker algorithm you can follow my video on banker's algorithm next one is deadlock detection and recovery what is the concept of deadlock detection and recovery is dialogue detection means we are trying to detect like by making the resource allocation graph for other methods we are trying to detect first whether there is a or not and when we detect it then we are trying to recover our system so that is also a kind of little complex because deadlock detection is also complex and after direction we are trying to recover also so it will make the system again very complex so what is the concept says first of all we are trying to detect after detection if say there is no download so nothing we don't need to do anything but if there is a deadlock we are trying to do some recovery recovery simply says let's say one method is kill the process kill the processes can the processes or a process means just simply kill like whatever the processes which are in the deadlock situation let's say two to three processes are in the deadlock situation either we try to kill one of the process and then we will check again that we will again detect there is still deadlock or not if there is no deadlock no problem if there is still that lock we will kill one more we will kill two then we will again detect give others there is a deadlock or not if it is deadlocked we will kill the third also means we are trying to kill all the processes which are in the deadlock situation so definitely it will hamper the performance of the system also but that is just a method key recovery say simply killing the process is one by one one more thing can be done resource preemption resource preemption means what we are trying to do is we will preempt the resource from a process means the process has taken some of the resource waiting for some other resource we will priam to the whatever resource it is holding although it is again kind of fuzzy method key how we can prevent a preempt the resource from a process but still that is just a method kind of theoretical method we are trying to simply recover the system from the deadlock by detecting it and then if dialogue we are trying to kill some of the processes let's say ten lower priority processes the processes which is having lowest priority we try to kill them or we are trying to take the resources back from one of the process or two of the process just to just to remove the deadlock from the system so this is what the how the various methods which are used what is a ignorance prevention deadlock avoidance and detection and recovery and you will be shocked to know if this method is real life implementation deadlock ignorant although other methods are also implemented but this is the most widely used method that is just the deadlock ignorance so this is all about the various methods to handle the deadlock so if you like the video please share it with your friends and colleagues and please subscribe my channel thank you
Info
Channel: Gate Smashers
Views: 306,765
Rating: 4.9459333 out of 5
Keywords: GATE, gate, cbse net, CBSE NET, VARUN SINGLA, VARUN SINGLA LPU, GATE SMASHERS, gate smashers, normal forms operating system tutorial, varun singla in gate smashers gate tutorial for operating system, operating system tutorials, Deadlock Handling Methods, Deadlock Prevention, deadlock, deadlock in operating system
Id: pPM9Ajqmy_4
Channel Id: undefined
Length: 24min 49sec (1489 seconds)
Published: Tue Mar 20 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.