Professional Documents
Culture Documents
Deadlock Detection, Recovery and Avoidance: Project On
Deadlock Detection, Recovery and Avoidance: Project On
DEADLOCK DETECTION,
RECOVERY AND AVOIDANCE
Submitted By:
Praveen Dewani 8103524
Batch B-5
DEADLOCKS
A deadlock is a situation where in two or more competing actions are each
waiting for the other to finish, and thus neither ever does.
Ignore the problem altogether ie, Ostrich algorithm .It may occur very
infrequently, cost of detection/prevention etc may not be worth it.
Detection and Recovery
Avoidance by careful resource allocation
Prevention by structurally negating one of the four necessary conditions.
Prevention
Difference from avoidance is that here, the system itself is build in such a way
that there are no deadlocks.
Avoidance
To avoid deadlocks, we try to make only those transitions that will take you
from one safe state to another. We avoid transitions to unsafe state.
Detection
Detecting a deadlock that has already occurred is easily possible since the
resources that each process has locked and/or currently requested are known
to the resource scheduler or OS. A special resource-allocation graph algorithm
can be used to detect whether there is any deadlock in the system. A resource-
allocation graph is a directed graph consisting of two different types of
nodes P = P1, P2,..., Pn, the set consisting of all active processes in the
system, and R = R1, R2,..., Rm, the set consisting of all resource types in the
system.
Recovery
Through preemption
Rollback
o Keep checkpointing periodically
o When a deadlock is detected, see which resource is needed.
o Take away the resource from the process currently having it.
o Later on, you can restart this process from a check pointed state
where it may need to reacquire the resource.
Killing processes
o Where possible, kill a process that can be rerun from the beginning
without ill effects.
ALGORITHMS USED
Deadlock Avoidance-Bankers Algorithm
STEP 1: Initialize
(a) Work=Available
(b) Finish[i] = false for i=0..n
Finish[i] = true
Goto STEP2
(a) Work=Available
(b) For i=1,2,...,n
If Allocation i ≠ 0
Then Finish[i] = false
Else Finish[i] = true
Finish[i] = true
Goto STEP2