 Hello everyone. Now in this lecture we are going to learn about methods for handling deadlock. The learning outcome of this session are at the end of this session student will be able to describe what are different methods for handling deadlock. Now first we will see how to deal with a deadlock problem. Now in previous videos we studied that how deadlock can occur into the system and there are four necessary conditions for deadlock to occur that is mutual exclusion, hold and wait, no preemption and circular wait. So if all these four conditions are exist simultaneously in the system then deadlock may occur and if that deadlock occurs in the system then how to deal with that deadlock problem. So first is either we have to use a protocol to prevent or avoid a deadlock. This means while designing a system design a protocol or use a protocol to prevent deadlock either prevent that deadlock or either avoid that deadlock means that deadlock should never occur into the system. Second if we don't have a deadlock prevention or deadlock avoidance then allow system to enter into deadlock state, detect it and then recover it means we don't have deadlock prevention scheme, we don't have deadlock avoidance scheme then obviously system will enter in deadlock state. Then if system enters into the deadlock state then we have to detect or the system have to detect the deadlock why and how it was occurred and once the detection is done then recover the system from the deadlock. Third case is ignore the problem altogether and pretend that deadlock never occurred into the system. So the third stage is what deadlock occurred but pretend that like that nothing has happened and ignore that problem of deadlock and continue your task or you can directly restart your system. Instead of detecting the deadlock instead of recovery from the deadlock behave like that deadlock was never occurred into the system. So these are the three cases how we can deal with deadlock first either prevent or avoid. If you don't have prevention and avoidance mechanism then deadlock will occur into the system if it is occurred then detect it and recover it otherwise ignore the problem and pretend that deadlock never occurred into the system. So to ensure that deadlock never occurred the system can use either deadlock prevention or deadlock avoidance scheme. Now how to handle with deadlock? Now deadlock prevention what is deadlock prevention? Deadlock prevention is a set of methods for ensuring that at least one of the necessary conditions cannot hold in the system. Now that necessary conditions are mutual exclusion, hold and wait, no preemption and circular wait. So deadlock prevention means what one of these conditions should not occur into the system because if four conditions simultaneously exist in the system then deadlock will occur. So design such a mechanism that one of the condition will never satisfy or one of the condition never hold in the system. So this method prevents deadlock by constraining how request for the resources can be made. This is the deadlock prevention scheme. Now in deadlock avoidance deadlock avoidance requires that the operating system be given in advance the additional information concerning which resources a process will request during its lifetime. Means what in deadlock avoidance before starting execution of any process that process must give additional information to the system that how many number of resources that process is going to request and use during its lifetime. So here system must have a prior knowledge for deadlock avoidance and for deadlock prevention we are saying that one of the conditions should not hold into the system. So this is what the deadlock prevention and deadlock avoidance we can apply in a system. So here decide for each request whether or not the process should wait. So in deadlock avoidance scheme we also have to decide that means system also have to decide that for every request made by that process whether or not that process should wait. So to decide whether the current request can be satisfied or whether it must be delayed the system must consider the number of resources currently available then the number of resources currently allocated to each process the future request and release of each process. So this is how the processes this is how the system must have a prior knowledge in case of a deadlock avoidance. Whenever process makes a request for new resource then check whether that resource are currently available or not whether it can be allocated to the process or not and the future what are the future request and release of the each process all these conditions we have to keep in mind. So just pause the video and write down the answer for what will happen if system does not imply either deadlock prevention or deadlock avoidance mechanism. If system do not have a deadlock prevention or deadlock avoidance then system may enter into the deadlock state and system can provide an algorithm that examine the state of the system. So deadlock prevention and avoidance must be there in a system. If it is not then deadlock may occur into the system. So to provide the algorithm the system examine the state of the system to determine how it will examine the state it will determine whether deadlock has occurred in the system and if it is occurred then there should be a recovery mechanism from the deadlock in the system. Now handling of the deadlock. Suppose we have no mechanism for deadlock detection and recovery then the system is in deadlock state and there is no way of recognizing what was happened. If your system do not have any mechanism for deadlock detection or recovery then the system is in deadlock state but we cannot user cannot recognize that what was happened. So this undetected deadlock will result in deterioration of the system performance. How it will affect your system? First all the resources being held by the process that cannot run. Resources are already tied up. Server and more process may enter into the waiting state and they make request for resource and they enter in a deadlock state. They make a request for resources and enters in a deadlock state. So whole system resources are tied up all the processes are in waiting state then your system cannot perform any task. So system will stop functioning and we will need to be restarted manually. So if your system does not support for deadlock avoidance or deadlock prevention or deadlock detection and recovery then system will stop functioning. We have to shut down our system or we have to restart our system manually and after restart also if does not happens then we have to format our system that is the case. So in many system deadlock occurs infrequently. Sometimes system is in frozen state but it is not in deadlock state. So deadlock state is different and frozen state is different. Deadlock state means no task is performed by the process and frozen state means consider a real time process which is running some higher priority process. Higher priority process is running or we have a non preemptive scheduler. Now non preemptive scheduler means that scheduler will never print the resources or it will not print any process till it completes its task means your CPU is in working condition but as it is performing either some higher priority process or your CPU scheduler is non preemptive scheduler then what will happen till the execution of such process it will never return a control to the operating system. It will never return control to the operating system and that system enters into the frozen state still that process completes its execution but this is not a deadlock state. So thus the system must have manual recovery method for non deadlock conditions and may simply use the techniques for the deadlock recovery. So in such case we must have some manual recovery methods for non deadlock conditions and we may simply use such techniques for the recovery of the deadlock. So this is how the deadlock prevention or a deadlock avoidance mechanism must present in the system and if system enters into the deadlock state then there must be a deadlock recovery mechanism in the system. So this is what how we can deal or how we can handle the deadlock in the system. So these are the references. Thank you.