Operating System Seminar Topic: Dead Lock Detection: Name: Gopisetty Nagendra REG NO: 11199A081
Operating System Seminar Topic: Dead Lock Detection: Name: Gopisetty Nagendra REG NO: 11199A081
DeadLock:
In an Operating System,deadlock occurs when a
process or thread enters a waiting state because
a requested system resource is held by another
waiting process, which in turn is waiting for
another resource held by another waiting process.
If a system is in safe state ⇒ no deadlocks.
If a system is in unsafe state ⇒ possibility of
deadlock.
Avoidance ⇒ ensure that a system will never
enter an unsafe state.
Single Instance of Each Resource Type
Maintain wait-for graph
Nodes are processes.
Pi → Pj if Pi is waiting for Pj .
Periodically invoke an algorithm that
searches for a cycle in the graph.
An algorithm to detect a cycle in a
graph requires an order of n2
operations, where n is the number of
vertices in the graph.
Resource Allocation Graph and
Wait-for Graph
If all resources have only a single instance, then we can define a deadlock-
detection algorithm that uses a variant of the resource-allocation graph, called
a wait-for graph.
This graph is obtained from the resource-allocation graph by removing the
resource nodes and collapsing the appropriate edges.
More precisely, an edge from to in a wait-for graph implies that process is
waiting for process to release a resource that needs.
Dead Lock Detection
If resources have single instance:
In this case for Deadlock detection we can run an
algorithm to check for cycle in the Resource
Allocation Graph. Presence of cycle in the graph is
the sufficient condition for deadlock.
Result:
Sequence <p0, p2,p3,p1,p4>will result in Finish[i] = true for all i.
Detection-Algorithm Usage
When, and how often, to invoke depends
on:
How often a deadlock is likely to occur?
How many processes will need to be rolled
back? ! one for each disjoint cycle
If detection algorithm is invoked arbitrarily,
there may be many cycles in the resource
graph and so we would not be able to tell
which of the many deadlocked processes
“caused” the deadlock
Recovery from Deadlock: Process
Termination
Abort all deadlocked processes.
Abort one process at a time until the deadlock
cycle is eliminated.
In which order should we choose to abort? ●
Priority of the process. ● How long process
has computed, and how much longer to
completion. ● Resources the process has
used. ● Resources process needs to complete.
● How many processes will need to be
terminated. ● Is process interactive or batch?
Recovery from Deadlock: Resource
Preemption
Selecting a victim – minimize cost.
Rollback – return to some safe state,
restart process for that state.
Starvation – same process may always
be picked as victim, include number of
rollback in cost factor.
Deadlock Recovery
A traditional operating system such as Windows doesn’t deal with
deadlock recovery as it is time and space consuming process. Real-
time operating systems use Deadlock recovery.
Recovery method