Deadlock in Operating System
Deadlock in Operating System
The computer system uses may types of resource which are then used by various
processes to carry out their individual functions. But problem is that the amount of
resources available is limited and many processes need to use it. A set of process is
said to be in a deadlocked state when every process in the set is waiting for an event
that can be caused only by another process in the set. The event can be resource
acquisition, resource release etc. The resource can be physical (printers, memory
space) or logical (semaphores, files)
There are two types of deadlock avoidance algorithms on the basis of their
resources:
Algorithm which is used for single instance of a resource type is Resource-
allocation graph. This algorithm uses the resource allocation graph by
introducing a new edge called claim edge. The claim edge is used to indicate that
a process may request a resource in future. It is represented by a dashed line.
When the process requests that resource, the dashed line is converted to an
assignment edge. i.e. a solid line. It indicates that the resource has been allocated
to the process. After the process releases this resource, the assignment edge is
again converted to claim edge. When a process requests a resource, it is
allocated only if converting the request edge to an assignment edge does not
form a cycle in the graph. If no cycle is formed, the system is in safe state and the
resource will be allocated. But if there is a cycle, the system will enter an unsafe
state and the process will wait for the resource.
• Mutual exclusion
• Wait and hold
• No pre-emption
It prevents Circular wait
Let n be the number of processes and m be the number of the resource type.
Following data structures are required:
After the detection of deadlock, a method must require to recover that deadlock to run
the system again. The method is called as deadlock recovery.
The ability to take a resource away from a process, have another process use it, and
then give it back without the process noticing. It is highly dependent on the nature of
the resource.
To do the recovery of deadlock, a process that owns a needed resource is rolled back to
a point in time before it acquired some other resource just by starting one of its earlier
checkpoints.
This method of deadlock recovery through killing processes is the simplest way of
deadlock recovery.
Sometime it is best to kill a process that can be return from the beginning with no ill
effects.