In this blog we are going to talk about how to prevent dead lock, preventing dead lock is one of the most important concern of operating system in this blog, I am going to cover what are the necessary condition to lead deadlock and what are various way to prevent these condition to happen
To Know some details about dead lock and RAG click here
Table of Condition
- Necessary condition to lead Dead
- How to prevent these condition to happen
In order to prevent dead lock, there is need to check for the condition in which dead lock occurs. There is total four conditions, if they occur simultaneously in the system then definitely there exist a dead lock.
Four condition for dead lock is as follows
- Mutual exclusion
- Hold and Wait
- Circular wait
Mutual exclusion: according to this condition resources will be either allocated to one process or it is freely available means one resource is allocated to only one process it is not shareable. there should be one to one relationship between resource and process.
Hold and Wait: The process is holding a resource and waiting on some other resource simultaneously is called Hold and Wait condition.
Non-Preemption: the resource has to be released by the process voluntarily after completion of execution it not allowed to preempt resource from the process force fully.
Circular Wait: the processes are waiting for each other circularly for the resource.
Here R1 is allotted P1, waiting for R2 but R2 is allocated to P2 and P2 is waiting for P1 to release R1 this wait is called circular wait.
How to prevent these condition to happen
In order to Prevent deadlock, there is need to dissatisfy the above condition mean here we are trying to prevent the condition to be happen.
It is not possible to dissatisfy mutual exclusion because of shared and not shared resources. For example, file is shareable resource and Printer are not shareable resource.
Hold and wait
We can remove hold and wait condition by applying two procedure
By allocation all the resources required by process in advance means before starting it execution
But there is one problem with this solution this will reduce the utilization of devices. As process is holding all the resources but not using it.
Second approach is process will release the existing resources before making new request.
This will lead to the starvation.
#deadlock prevention in OS, #deadlock problems and solutions in operating system, #how can we resolve deadlock?, #deadlock condition in OS, #deadlock prevention in OS tutorial, #deadlock detection in OS