0% found this document useful (0 votes)
53 views16 pages

Operating System Seminar Topic: Dead Lock Detection: Name: Gopisetty Nagendra REG NO: 11199A081

This document discusses deadlock detection and recovery in operating systems. It begins with basic facts about deadlocks, including that they occur when a process is waiting for a resource held by another waiting process. It then discusses different algorithms for detecting deadlocks depending on whether resources have a single instance or multiple instances. For single instances, it checks for cycles in the resource allocation graph. For multiple instances, it uses a vector-based algorithm that tracks available and allocated resources. The document ends by discussing different approaches for recovering from a detected deadlock, such as terminating processes or preempting resources from processes.

Uploaded by

Nuthan Prasad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views16 pages

Operating System Seminar Topic: Dead Lock Detection: Name: Gopisetty Nagendra REG NO: 11199A081

This document discusses deadlock detection and recovery in operating systems. It begins with basic facts about deadlocks, including that they occur when a process is waiting for a resource held by another waiting process. It then discusses different algorithms for detecting deadlocks depending on whether resources have a single instance or multiple instances. For single instances, it checks for cycles in the resource allocation graph. For multiple instances, it uses a vector-based algorithm that tracks available and allocated resources. The document ends by discussing different approaches for recovering from a detected deadlock, such as terminating processes or preempting resources from processes.

Uploaded by

Nuthan Prasad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 16

Operating System Seminar

Topic: Dead Lock Detection

NAME: GOPISETTY NAGENDRA


REG NO: 11199A081
Deadlock Detection

 Allow system to enter deadlock state


 Detection algorithm
 Recovery scheme
Basic Facts

 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.

In the above diagram, resource 1 and resource 2


have single instances. There is a cycle R1 → P1 →
R2 → P2. So, Deadlock is Confirmed.
Several Instances of a Resource Type
 Available: A vector of length m indicates the
number of available resources of each type.
 Allocation: An n x m matrix defines the
number of resources of each type currently
allocated to each process.
 Request: An n x m matrix indicates the
current request of each process. If Request
[i j ] = k, then process Pi is requesting k
more instances of resource type. Rj .
DeadlockDetection Algorithm
1.Let Work and Finish be vectors of length m and n respectively.
Initialize Work= Available. For i=0, 1, …., n-1,
if Requesti = 0, then Finish[i] = true; otherwise, Finish[i]= false.

2.Find an index i such that both 


a) Finish[i] == false 
b) Requesti <= Work 
If no such i exists go to step 4.

3.Work= Work+ Allocationi 


Finish[i]= true 
Go to Step 2.

4.If Finish[i]== false for some i, 0<=i<n, then the system is in a deadlocked state.


Moreover, if Finish[i]==false the process Pi is deadlocked.

• Algorithm requires an order of O(m x n2) operations to detect whether the


system is in deadlocked state.
Example of Detection Algorithm
Five processes p0 through p4 through resource types A(7 instances),B(2 instances),C(6 instances)

1. In this, Work = [0, 0, 0] & 


p0 p1 p2 p3 p4
Finish = [false, false, false, false, false]
 
2. i=0 is selected as both Finish[0] = false and
[0, 0, 0]<=[0, 0, 0].
 
3. Work =[0, 0, 0]+[0, 1, 0] =>[0, 1, 0] & 
p0 p1 p2 p3 p4
Finish = [true, false, false, false, false].
Continue of example

4. i=2 is selected as both Finish[2] = false and [0, 0, 0]<=[0, 1, 0].

5. Work =[0, 1, 0]+[3, 0, 3] =>[3, 1, 3] & 


p0 p1 p2 p3 p4
Finish = [true, false, true, false, false].
 
6. i=1 is selected as both Finish[1] = false and
[2, 0, 2]<=[3, 1, 3].

7. Work =[3, 1, 3]+[2, 0, 0] =>[5, 1, 3] & 


p0 p1 p2 p3 p4
Finish = [true, true, true, false, false].
 
8. i=3 is selected as both Finish[3] = false and
[1, 0, 0]<=[5, 1, 3].

9. Work =[5, 1, 3]+[2, 1, 1] =>[7, 2, 4] & 


p0 p1 p2 p3 p4
Finish = [true, true, true, true, false].
Continue of example

10. i=4 is selected as both Finish[4] = false


and [0, 0, 2]<=[7, 2, 4].
 
11. Work =[7, 2, 4]+[0, 0, 2] =>[7, 2, 6] & 
p0 p1 p2 p3 p4
Finish = [true, true, true, true, true].
 
12. Since Finish is a vector of all true it means there is no deadlock in
this example.

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

 Killing the process: killing all the process involved in the deadlock.


Killing process one by one. After killing each process check for
deadlock again keep repeating the process till system recover from
deadlock.
 Resource Preemption: Resources are preempted from the processes
involved in the deadlock, preempted resources are allocated to other
processes so that there is a possibility of recovering the system from
deadlock. In this case, the system goes into starvation.
Thank You
Gopisetty Nagendra

You might also like