Professional Documents
Culture Documents
Deadlock Detection and RecoveryLecture 3
Deadlock Detection and RecoveryLecture 3
Reference Book
Operating System Concepts 9th Edition
Avi Silberschatz, Peter Baer Galvin and Greg Gagne
Ibrar Afzal
Lecturer
IT Department HU Mansehra
1
Deadlocks Detection
Need an algorithm that determines SINGLE INSTANCE OF A RESOURCE TYPE
if deadlock occurred.
• Wait-for graph == remove the resources
Also need a means of recovering from the usual graph and collapse edges.
from that deadlock. • An edge from p(j) to p(i) implies that p(j) is
waiting for p(i) to release.
2
Deadlocks Detection
In the diagram, resource 1 and resource 2 have single instances.
There is a cycle
R1 → P1 → R2 → P2.
Deadlock is Confirmed.
3
Deadlocks Detection
In this case, the system may or may not be in deadlock varies according to
different situations.
4
Deadlocks Detection
5
Deadlocks Detection
6
Deadlocks Detection
EXAMPLE
We have three resources, A, B, and C. A has 7 instances, B has 2 instances, and C has 6
instances. At this time, the allocation, etc. looks like this:
7
Deadlocks Detection
EXAMPLE
Suppose the Request matrix is changed like this. In other words, the maximum amounts to be allocated
are initially declared so that this request matrix results.
Is there now a
sequence that will Alloc Req Avail
allow deadlock to be
avoided? A B C A B C A B C
P0 0 1 0 0 0 0 0 0 0
USAGE OF THIS P1 2 0 0 2 0 2
DETECTION ALGORITHM P2 3 0 3 0 0 1#
Frequency of check P3 2 1 1 1 0 0
depends on how often a
deadlock occurs and how P4 0 0 2 0 0 2
many processes will be
affected.
8
Deadlocks Recovery
9
Deadlocks Recovery
Process Termination
Deadlock has occurred?
Inform the operator that a deadlock has occur and to permit the
10
Deadlocks Recovery
Process Termination
Deadlock has occurred , how do we get the resources back and gain forward
progress?
To remove deadlocks by aborting a process, we can use one of two methods.
Abort all deadlocked processes.
In both methods, the system regain all resources allocated to the terminated
Processes.
11
Deadlocks Recovery
Process Termination
The deadlocked processes may have computed for a long time, and the
results of these partial computations must be discarded and probably will
have to be recomputed later.
12
Deadlocks Recovery
Process Termination
:
13
Deadlocks Recovery
Process Termination
Is this a Simple and straightforward approach?
NO
Why???
If the process was in the midst of updating a file,
Terminating it will leave that file in an erroneous state.
14
Deadlocks Recovery
Process Termination
15
Deadlocks Recovery
Resource Preemption
16
Deadlocks Recovery
Resource Preemption
Yes
•But after solving three main issues related with Resource
Preemption
1. Selecting a victim
2. Rollback
3. Starvation.
17
Deadlocks Recovery
Resource Preemption
1. Selecting a victim.
Which resources and which processes are to be preempted?
18
Deadlocks Recovery
Resource Preemption
2. Rollback
If we preempt a resource from a process, what should be done with that process?
Process cannot carry on with its normal execution because
It is more effective to roll back the process only to break the deadlock
But this method want the system to keep more information about the state of all
running processes.
19
Deadlocks Recovery
Resource Preemption
3. Starvation.
•How do we ensure that starvation will not occur?
•Is there a guarantee that same process will preempted for a resource?
•But in a system where victim selection is based mainly on cost factors,
•It may happen that the same process is always picked as a victim.
•As a result, this process never completes its designated task, a starvation
situation any practical system must address.
• Make it sure that a process can be picked as a victim only a (small) finite number of
times.
•The most common solution is to include the number of rollbacks in the cost factor.
20
Thanks
21