Deadlocks in Operating Systems
Deadlock is one of the underlying topics in Operating Systems. Deadlock is nothing but when two or more processes are waiting on happening of some event to occur, which never happens then we say these processes are in deadlock.
Deadlock can arise if these four conditions occur simultaneously
Mutual Exclusion: At least one resource must be held in a non-shareable.
Hold and Wait: A process is holding at least one resource and waiting for other resources that are being currently held by other processes.
No Preemption: A resource cannot be preempted that is a resource can be released only voluntarily by the process holding it.
Circular Wait: A set of processes are waiting for each other’s resources in a circular form.
Methods for handling deadlock
There are three ways to handle deadlock
1) Deadlock prevention or avoidance: Provides a set of methods to ensure that at least one of the necessary conditions cannot hold. One can zoom into each category individually, Prevention is done by negating one of the above-mentioned necessary conditions for deadlock.
Avoidance is kind of futuristic in nature. By using the strategy of “Avoidance”, we have to make an assumption. We need to ensure that all information about resources that the process will need is known to us prior to the execution of the process. We use Banker’s algorithm (Which is in turn a gift from Dijkstra) in order to avoid deadlock.
2) Deadlock detection and recovery: Let deadlock occur, then do preemption to handle it once occurred.
3) Ignore the problem altogether: In some cases, the occurrence of deadlock is very rare, then let it happen and reboot the system. This is the approach that both Windows and UNIX take.