Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
46 views67 pages

Deadlock

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1/ 67

Operating Systems

Deadlock
By
Dr. Sidra Rafique
Introduction to Deadlock
 A set of processes is said to be in a dead lock state if every process
is waiting for an event that can be caused only by another process
in the set.
 A set of blocked processes each holding a resource and waiting to
acquire a resource held by another process in the set.
 A process is said to be dead locked if it is waiting for an event
which will never occur.
 Example
A table with a writing pad and a pen.
Two persons sitting around the table wants to write letter.
One picks up the pad and the other grab the pen.
Dead Lock!

2
Introduction to Deadlock
 Example 1
 Consider a system having two tape drives.
 P1 and P2 each hold one tape drive and each needs the other
one(e.g. to copy data from one tape drive to the other).
 Example 2
 Semaphores A and B, initialized to 1
P0 P1
signal(A);
wait (A); wait(B);
wait (B); wait(A);
--- --- P0 P1

signal(B);

3
Introduction to Deadlock
 Example 3
 The Dining Philosophers problem … all philosophers become
hungry at the same time, pick up the chopsticks on their right and
wait for getting the chopsticks on their left.
 Example 4
• Consider a one way bridge.
• Each section of a bridge can be viewed as a resource.
• If a deadlock occurs, it can be resolved if one car backs up
(preempt resources and rollback).

4
Introduction to Deadlock
 Is deadlock the same as starvation?
 A process is indefinitely postponed if it is delayed repeatedly over
a long period of time while the attention of the system is given to
other processes. i.e., logically the process may proceed but the
system never gives it the CPU.

5
Resources
 Deadlocks occurs when processes have been granted exclusive access to
resources; In case of sharable access DL will not occur.
 A resource can be a hardware device (e.g. tape drive, printer, memory,
CPU) or a piece of information (a variable, file, semaphore, record of a
database).
 Resources comes in two flavors:
Preemptable Resources. A resource that can be taken away from the
process holding it with no ill effects,(sharable resources) e.g. CPU, memory.
Non Preemptable Resources. A resource that cannot be taken away from
the process holding it, w/o causing the computation to fail, (non sharable
resources) e.g. if a process has begun to burn a CD ROM, suddenly taking the
CD recorder away from it and giving the CD Recorder to another process will
result in a garbled CD.
 In general DL involve non preemptable resources.
 A process may utilize a resource in following sequence:
Request  Use  Release
6
Conditions for Deadlock
Deadlock can arise if four conditions hold simultaneously.
 Mutual exclusion: Only one process at a time can use a
resource.
 Hold and wait: A process holding one or more allocated
resources while awaiting assignment of other.
 No preemption: No resource can be forcibly removed from a
process holding it.
 Circular wait: There exists a set {P0, P1, …, Pn} of waiting
processes such that P0 is waiting for a resource that is held by
P1, P1 is waiting for a resource that is held by P2, …, Pn–1 is
waiting for a resource that is held by
Pn, and Pn is waiting for a resource that is held by P0.
P0 → P1 → P2 → … → Pn → P0

7
Resource Allocation Graph (RAG)
 A set of vertices V and a set of edges E.
 V is partitioned into two types:
P = {A set of processes} = {P1, P2, …, Pn}
R = {A set of Resources} = {R1, R2, …, Rm}
 E = {Request Edges, Assignment Edges}
Request Edge: P1  Rj
Assignment Edge: Rj  Pi

 Process
P R
 Resource Type with 4 instances

 Pi requests instance of Rj Pi

8 Pi
 Pi is holding an instance of Rj
RAG – Examples

9
Determining Deadlock using RAG

RAG with cycles but RAG with cycles


10 No Deadlock with a Deadlock
Deadlock Handling
Generally speaking we can deal with DL problem in one of
three ways:
 Ensure that the system will never enter a deadlock state.
 Ignore the problem and pretend that deadlocks never occur in
the system.
 Allow the system to enter a deadlock state and then recover.
Methods Used for DL Handling
Deadlock prevention. (Involves adopting a static policy that disallows one of
the four conditions for dead lock) .
Deadlock avoidance. (Involves making dynamic choices that guarantee
prevention).
Deadlock detection and recovery. (Involves recognizing when deadlock
has occurred, and trying to recover).

11
Deadlock Prevention
Restrain the ways resource allocation requests can be
made, to ensure that at least one of the four necessary
conditions is violated.
i. Mutual Exclusion.
ii. Hold and Wait.
iii. No Preemption.
iv. Circular Wait.

12
Deadlock Prevention
i. Mutual Exclusion.
Cannot be prevented for all resources. Some resources
are inherently non-sharable because their states cannot
be saved and restored without ill effects, such as a
printer.

13
Deadlock Prevention
ii. Hold and Wait
We must guarantee that whenever a process requests a
resource, it does not hold any other resources.
Option 1 - Deny wait.
Allocate the process with all the requested
resources before it starts execution. If one or more
resources are busy, nothing would be allocated and
the process would just wait. (Low resource
utilization)
Option 2 - Deny hold.
A process may request some resources and use
them. But before requesting any additional
resources, it must release all the resources that are
currently allocated. (Possibility of starvation)
14
Deadlock Prevention
iii. No Preemption
If a process that is holding some resources requests
another resource that cannot be immediately allocated to
it, then all resources currently being held are released.
Preempted resources are added to the list of resources
for which the process is waiting for.
Process will be restarted only when it can regain its old
resources as well as the new ones that it has requested.
This protocol is often applied to resources whose state
can be easily saved and restored later, such as CPU
registers and memory space. It cannot generally be
applied to such resources as printers and tape drives. (Its
difficult to take a tape drive away from a process that is busy writing a tape).

15
Deadlock Prevention
iv. Circular Wait
Impose a total ordering of all resource types, and
require that each process requests resources in an
increasing order of enumeration.
We assign a unique number to each resource type by
using function
F: R → N
and make sure that processes request resources in an
increasing order of enumeration.
Example
Tape drive = 1, Disk drive = 5, and Printer = 12.
P1 holding Tape can request for both DD and Printer.
P2 holding DD can request for Printer but not for TD.
16
Deadlock Prevention (cont…)
Circular wait (Proof)
Lets assume that a cycle exist among processes:
P0 → P1 → P2 → … → Pk → P0

R0 R1 R2 Rk R0
P0 is holding R0 and waiting for P1 to release R1;
P1 is holding R1 and waiting for P2 to release R2 and so on.
As per rule of circular wait:
  F(R0) < F(R1) < … F(Rk) < F(R0)
  F(R0) < F(R0), which is impossible
  There can be no circular wait.
17
Deadlock Avoidance
 The implementation of deadlock avoidance requires that the
system has an advanced information available about the
future use of resources by processes.
 Simplest way is that each process declare the maximum
number of resources of each type that it may need.
 The deadlock-avoidance algorithm dynamically examines the
resource-allocation state to ensure that there can never be a
circular-wait condition.
 Resource-Allocation state is defined by the total number of
resources available in the system, maximum demands of the
processes and the number of resources allocated to the
processes.

18
Deadlock Avoidance (cont…)
 When a process requests an available resource, system must
decide if immediate allocation leaves the system in a safe state.
 System is in a safe state if there is at least one sequence of
allocation of resources to processes that does not result in a
dead lock. (Sequence of processes does not matter).
 Safe Sequence is the sequence of execution of processes in
which OS fulfills requests of all the processes and still avoids
dead lock.
 Basic Facts.
 If a system is in safe state  no deadlocks.
 If a system is in unsafe state  possibility of deadlock due to
the behavior of processes.
19
Deadlock Avoidance (cont…)
 DL Avoidance ensure that a system never enters in unsafe state.
 A system can be in safe or unsafe state. Unsafe state does not
necessarily means that system is in DL. It may lead to a DL.

20
Example 1
 System with 12 tape drives and three processes
 Current system state:
Process Max Need Allocated Max. Future Need
P0 10 5 5
P1 4 2 2
P2 9 2 7

 System is in a safe state with the safe sequence


<P1, P0, P2>
Example 2
 Assuming that P2 request for a tape drive and is
allocated to it, the new system state will be:
Process Max Need Allocated Max. Future Need
P0 10 5 5
P1 4 2 2
P2 9 3 6

 System gets into an unsafe state.


Example 3
 Given 5 total units of the resource, tell whether the
following system is in a safe or unsafe state.
Process Max Need Allocated Max. Future Need
P0 2 1 1
P1 3 1 2
P2 4 2 2
P3 5 0 5
Example 4
 Given a total of 10 units of a resource type, and given
the safe state shown below, should P2 be granted a
request of 2 additional resources?
Process Max Need Allocated Max. Future Need
P0 5 2 3
P1 6 1 5
P2 6 2 4
P3 2 1 1
P4 4 1 3
RAG Algorithm
 Used for DL avoidance in case of single instance of each resource.
 Claim edge Pi  Rj indicates that process Pi may request an
instance of resource Rj; represented by a dashed line.
 Claim edge converts to request edge when a process requests a
resource.
 When a resource is assigned to a process, request edge
reconverts to an assignment edge.
 When a resource is released by a process, assignment edge
reconverts to a claim edge.
 All processes will inform the algo in advance which resources
they will be requiring in their life cycle.

25
RAG Algorithm (cont…)

Claim edge is converted to request edge


and then to assignment edge

Before converting a claim edge to request edge,


we need to check whether it will create a cycle in the directed
Graph or not.

26
Banker’s Algorithm
 This is a deadlock avoidance algorithm for resources with multiple
instances.
 When a process initiates a request the algorithm checks whether
after the grant of this request the system will remain in safe
state. If yes the request is granted, if not the request is denied.
 Algorithm is based on resource denial if there is a suspected risk of
a deadlock.
 Each process must in advance inform the algo the number of
instances it may require in its life time.
 When a process requests a resource it may have to wait, i.e. in
case the system is going to unsafe state by allocation of that
resource; the process must wait.
 When a process gets all its resources it must return them in a finite
amount of time.
27
Data Structures for the Banker’s Algorithm
 n = Number of processes.
 m = Number of resource types.

 Available: Vector of length m, indicates the number of available


instances of resources of each type. Available[j] = k means that
there are k available instances of resource type Rj.
 Max: n x m matrix, indicates the maximum demand of resources of each
process. Max[i,j] = k means that process Pi may request at most k
instances of resource type Rj.
 Allocation: n x m matrix, indicates the no of instances of resources of
each type currently allocated to each process. Allocation[i,j] = k means
that Pi is currently allocated k instances of resource type Rj.
 Need: n x m matrix indicates the remaining resource need of each
process. Need[i,j] = k means Pi may need k more instances of Rj to
complete its task.
Need[i,j] = Max[i,j] – Allocation [i,j]

28
Safety Algorithm
 Used to determine whether or not a system is in safe
state.
 Check the system state and sees if there is any process
whose request can be fulfilled. If yes note it down in
safe sequence and then add its allocation vector in
available vector.
 So now we have got a new available vector with some
new instances of various resource types.
 The above step is repeated with all the processes and
finally either we will be able to finish all the processes
with a safe sequence OR we may get stuck.
 The safety algo returns safe or unsafe whatever is
29 applicable to the Bankers Algorithm.
Resource-Request Algorithm
Let Requesti be the request vector for process Pi.
If Requesti [j] = k then Pi wants k instances of resource type Rj.
1.If Requesti  Needi then
go to step 2
else
report error (since process has exceeded its maximum claim).
2.If Requesti  Available then
go to step 3
else
Pi must wait (since resources are not available).
3.Update system table:
Available = Available – Requestj;
Allocationi = Allocationi + Requesti;
Needi = Needi – Requesti;
30
Resource-Request Algorithm (cont…)

Now the Banker’s Algo invokes the safety algo with this new system
state and the safety algo tells the banking algo whether the new
state will be safe or not.
If safe  the resources are allocated to Pi.

 If unsafe  Pi must wait, and the old resource-allocation state is

restored

31
Safety Algorithm
1. Let Work and Finish be vectors of length m and n, respectively.
Initialize:
Work = Available;
for i = 1, 2, …, n
Finish[i] = false;
2. Find an index i such that both:
(a) Finish[i] == false (b) Needi  Work
If no such i exists, go to step 4.
3. Work = Work + Allocationi
Finish[i] = true, go to step 2.
(we are finding a process who has not finished yet and its need is
less than its allocation)
4. If Finish[i] == true, for all i, 1  i  n, then the system is in a safe
state.
32
Example 1
 Five processes: P0 … P4
 Three resource types: A (10 instances), B (5 instances), C (7 instances)
 System state is shown below:

Max Matrix Allocation Matrix Available Vector

Process
A B C A B C A B C
P0 7 5 3 0 1 0 3 3 2
P1 3 2 2 2 0 0
P2 9 0 2 3 0 2
P3 2 2 2 2 1 1
33
P4 4 3 3 0 0 2
Example 1 (cont…)

 Needi = Maxi – Allocationi


 Need matrix

Process A B C
P0 7 4 3
P1 1 2 2
P2 6 0 0
P3 0 1 1
P4 4 3 1
34
Example 1 (cont…)
Need Allocation Matrix Available Vector /
Work
Process
A B C A B C A B C
P0 7 4 3 0 1 0 3 3 2
P1 1 2 2 2 0 0
P2 6 0 0 3 0 2
P3 0 1 1 2 1 1
P4 4 3 1 0 0 2
Resources cant be granted to P0 as (7,4,3)>(3,3,2)
35
However, can be granted to P1 as (1,2,2)  (3,3,2)
Example 1 (cont…)

Need Allocation Matrix Available Vector /


Work
Process A B C
A B C A B C
P0 7 4 3 0 1 0 3 3 2
P1 1 2 2 2 0 0 5 3 2
P2 6 0 0 3 0 2
P3 0 1 1 2 1 1
P4 4 3 1 0 0 2

36
Safe Sequence: <P1>
Example 1 (cont…)

Need Allocation Matrix Available Vector /


Work
Process
A B C A B C A B C
P0 7 4 3 0 1 0 3 3 2
P1 1 2 2 2 0 0 5 3 2
P2 6 0 0 3 0 2 7 4 3
P3 0 1 1 2 1 1
P4 4 3 1 0 0 2

37
Safe Sequence: <P1, P3>
Example 1 (cont…)

Need Allocation Matrix Available Vector /


Work
Process
A B C A B C A B C
P0 7 4 3 0 1 0 3 3 2
P1 1 2 2 2 0 0 5 3 2
P2 6 0 0 3 0 2 7 4 3
P3 0 1 1 2 1 1 7 4 5
P4 4 3 1 0 0 2

38
Safe Sequence: <P1, P3, P4>
Example 1 (cont…)

Need Allocation Matrix Available Vector /


Work
Process
A B C A B C A B C
P0 7 4 3 0 1 0 3 3 2
P1 1 2 2 2 0 0 5 3 2
P2 6 0 0 3 0 2 7 4 3
P3 0 1 1 2 1 1 7 4 5
P4 4 3 1 0 0 2 7 5 5

39
Safe Sequence: <P1, P3, P4, P0>
Example 1 (cont…)

 Final safe sequence:


<P1, P3, P4, P0, P2>
 Not a unique sequence
 Possible safe sequences for the this
example:
<P1,P3,P4,P0,P2>, <P1,P3,P4,P2,P0>,
<P1,P3,P2,P0,P4>, <P1,P3,P2,P4,P0>,
<P1,P3,P0,P2,P4>, <P1,P3,P0,P4,P2>
40
Example 2
 P1 requests (1,0,2). Can this request be granted immediately?
Need Allocation Matrix Available Vector

Process A B C A B C A B C
P0 7 4 3 0 1 0 3 3 2
P1 1 2 2 2 0 0
P2 6 0 0 3 0 2
P3 0 1 1 2 1 1
P4 4 3 1 0 0 2
1. Is Request1  Need1? (1,0,2)  (1,2,2)  true
41
2. Is Request1  Available? (1,0,2)  (3,3,2)  true
Example 2 (cont…)

Need Allocation Matrix Available Vector /


Work
Process
A B C A B C A B C
P0 7 4 3 0 1 0 2 3 0
P1 0 2 0 3 0 2
P2 6 0 0 3 0 2
P3 0 1 1 2 1 1
P4 4 3 1 0 0 2

42
Safe Sequence: <>
Example 2 (cont…)

Need Allocation Matrix Available Vector /


Work
Process
A B C A B C A B C
P0 7 4 3 0 1 0 2 3 0
P1 0 2 0 3 0 2 5 3 2
P2 6 0 0 3 0 2
P3 0 1 1 2 1 1
P4 4 3 1 0 0 2

43
Safe Sequence: <P1>
Example 2 (cont…)

Need Allocation Matrix Available Vector /


Work
Process
A B C A B C A B C
P0 7 4 3 0 1 0 2 3 0
P1 0 2 0 3 0 2 5 3 2
P2 6 0 0 3 0 2 7 4 3
P3 0 1 1 2 1 1
P4 4 3 1 0 0 2

44
Safe Sequence: <P1, P3>
Example 2 (cont…)

Need Allocation Matrix Available Vector /


Work
Process
A B C A B C A B C
P0 7 4 3 0 1 0 2 3 0
P1 0 2 0 3 0 2 5 3 2
P2 6 0 0 3 0 2 7 4 3
P3 0 1 1 2 1 1 7 4 5
P4 4 3 1 0 0 2

45
Safe Sequence: <P1, P3, P4>
Example 2 (cont…)

Need Allocation Matrix Available Vector /


Work
Process
A B C A B C A B C
P0 7 4 3 0 1 0 2 3 0
P1 0 2 0 3 0 2 5 3 2
P2 6 0 0 3 0 2 7 4 3
P3 0 1 1 2 1 1 7 4 5
P4 4 3 1 0 0 2 7 5 5

46
Safe Sequence: <P1, P3, P4, P0>
Example 2 (cont…)
 Final safe sequence:
<P1, P3, P4, P0, P2>
 Therefore, P1’s request may be granted immediately.
 Example 3
 Can request for (0,2,0) by P0 be granted?
 Example 4
 Can request for (3,3,0) by P4 be granted?

47
Sample Problem
 Five processes: P0 … P3
 Three resource types: A (9 instances), B (3 instances), C (6 instances)
 System state is shown below:

Max Allocation Work / Available

Process
A B C A B C A B C
P0 3 2 2 1 0 0 0 1 1
P1 6 1 3 6 1 2
P2 3 1 4 2 1 1
P3 4 2 2 0 0 2
48
Deadlock Detection & Recovery
Both prevention and avoidance of deadlock lead
to conservative allocation of resources, with
corresponding inefficiencies.
Deadlock detection takes the opposite approach:
Make allocations liberally, allowing deadlock to
occur (on the assumption that it will be rare);
Apply a detection algorithm periodically to check
for deadlock;
Apply a recovery algorithm when necessary.

49
Dead Lock Detection Algorithm for Single Instance of
Each Resource Type
 This algorithm use wait-for-graph that can be derived from RAG.

 To derive a wait for graph, you collapse the resource node.

P i  Pj means Pi is waiting for Pj.


 If a cycle exist in the wait for graph we say that a deadlock exist.
 To detect deadlock, the system maintains the wait for graph and
periodically invokes an algorithm that searches for a cycle in the
wait-for graph.
 The algorithm is expensive—it requires an order of n2 operations,
where n is the number of vertices in the graph.

50
RAG and Wait-for Graph

Resource-Allocation Graph Corresponding wait-for graph


51
Dead Lock Detection Algorithm for Multiple Instances
of Each Resource Type
Data Structures
 Available: Vector of length m, indicates the number of
available instances of resources of each type.
Available[j] = k means that there are k available
instances of resource type Rj.
 Allocation: n x m matrix, indicates the no of instances
of resources of each type currently allocated to each
process. Allocation[i,j] = k means that Pi is currently
allocated k instances of resource type Rj.
 Request: n x m matrix indicates the current request of
each process. Request[i,j] = k means Pi is requesting k
more instances of Rj to complete its task.
52
Detection Algorithm
 Used to determine whether or not a system is in safe
state.
 Check the system state and sees if there is any process
whose request can be fulfilled. If yes note it down in
safe sequence and then add its allocation vector in
available vector.
 So now we have got a new available vector with some
new instances of various resource types.
 The above step is repeated with all the processes and
finally either we will be able to finish all the processes
with a safe sequence OR we may get stuck.
 The safety algo returns safe or unsafe whatever is
53 applicable to the Bankers Algorithm.
Detection Algorithm
1. Let Work and Finish be vectors of length m and n, respectively.
Initialize:
Work = Available;
for i = 1, 2, …, n
if Allocationi !=0
then
Finish[i] = false;
else
Finish[i] = true;
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, 1  i  n, then the system is in
54 deadlock state. Moreover, if Finish[i] == false, then Pi is
deadlocked.
Example of Detection Algorithm
 Five processes: P0 … P4
 Three resource types: A (7 instances), B (2 instances), C (6 instances)
 System state is shown below:

Allocation Request Work / Available

Process
A B C A B C A B C
P0 0 1 0 0 0 0 0 0 0
P1 2 0 0 2 0 2
P2 3 0 2 0 0 0
P3 2 1 1 1 0 0
55
P4 0 0 2 0 0 2
Example (cont…)

Allocation Request Work / Available

Process
A B C A B C A B C
P0 0 1 0 0 0 0 0 0 0
P1 2 0 0 2 0 2 0 1 0
P2 3 0 2 0 0 0
P3 2 1 1 1 0 0
P4 0 0 2 0 0 2

56
Finish Sequence: <P0>
Example (cont…)

Allocation Request Work / Available

Process
A B C A B C A B C
P0 0 1 0 0 0 0 0 0 0
P1 2 0 0 2 0 2 0 1 0
P2 3 0 2 0 0 0 3 1 2
P3 2 1 1 1 0 0
P4 0 0 2 0 0 2

57
Finish Sequence: <P0, P2>
Example (cont…)

Allocation Request Work / Available

Process
A B C A B C A B C
P0 0 1 0 0 0 0 0 0 0
P1 2 0 0 2 0 2 0 1 0
P2 3 0 2 0 0 0 3 1 2
P3 2 1 1 1 0 0 5 2 3
P4 0 0 2 0 0 2

58
Finish Sequence: <P0, P2, P3>
Example (cont…)

Allocation Request Work / Available

Process
A B C A B C A B C
P0 0 1 0 0 0 0 0 0 0
P1 2 0 0 2 0 2 0 1 0
P2 3 0 2 0 0 0 3 1 2
P3 2 1 1 1 0 0 5 2 3
P4 0 0 2 0 0 2 5 2 5

59
Finish Sequence: <P0, P2, P3, P4>
Example (cont…)

 Final finish sequence:


<P0, P2, P3, P4, P1>
 Not a unique sequence
 Other Possible finish sequences for the this
example:
< P0, P2, P3, P1 , P4 >
< P0, P2, P4, P1 , P3 >
< P0, P2, P4, P3 , P1 >
..……………………………..
60
Example2
 P2 requests an additional instance of C.
 Do we have a finish sequence?

Allocation Request Work / Available

Process
A B C A B C A B C
P0 0 1 0 0 0 0 0 0 0
P1 2 0 0 2 0 2
P2 3 0 2 0 0 1
P3 2 1 1 1 0 0
61
P4 0 0 2 0 0 2
Example2 (cont…)

Allocation Request Work / Available

Process
A B C A B C A B C
P0 0 1 0 0 0 0 0 0 0
P1 2 0 0 2 0 2 0 1 0
P2 3 0 2 0 0 1
P3 2 1 1 1 0 0
P4 0 0 2 0 0 2

62
Finish Sequence: <P0>
Example2 (cont…)
 P0’s request can be satisfied with currently available
resources, but request for no other process can be
satisfied after that.
ÞDeadlock exists, consisting of processes
P1, P2, P3, and P4.

63
Deadlock Detection
How often should the detection algorithm be invoked?
1. Every time a request for allocation cannot be granted
immediately—expensive but process causing the deadlock
is identified, along with processes involved in deadlock.
2. Keep monitoring CPU usage, and when it goes below a
certain level, invoke the algorithm.
3. Run it periodically after a specified time interval.
4. Run the algo arbitrarily/randomly—In this case, we may
find a number of cycles in the system but may not be able
to find out which process has created these cycles.

64
Deadlock Recovery
Recovery algorithms vary a lot in their severity:
a) Process Termination:
Abort all deadlocked processes. Though drastic, this is probably
the most common approach!
Abort deadlocked processes one at a time until the deadlock no
longer exists. The aborted processes are called victims.
b) Resource Preemption :
Preempt resources until the deadlock no longer exists.

65
Deadlock Recovery
a) Process Termination:
In which order should we choose to abort processes?
1. Priority of a process.
2. How long the process has run.
3. Resources already used by a process.
4. Further resources the process needs to complete.
5. How many child processes will be needed to terminate.
6. Is the process interactive or batch?

66
Recovery from Deadlock
b) Resource Preemption :
In resource preemption, select a process and take back some
resources from that process and allocate those resources to other
requesting processes and bring the system out of deadlock.
Three important issues to be considered are:
 Selecting a victim – Which resources and which processes are to be
preempted?
 Rollback – If we preempt a resource from a process, what should be done
with that process? We need to return the victim to some safe state from
where it can be restarted later on.
 Starvation – There is a possibility that same process may always be picked
as victim, so to avoid this include number of rollbacks in cost factor of
victim selection.

67

You might also like