Professional Documents
Culture Documents
Operating Systems - CS604 Power Point Slides Lecture 29
Operating Systems - CS604 Power Point Slides Lecture 29
Systems
Lecture 29
Syed Mansoor Sarwar
of previous lecture
Deadlock detection: resources with
single and multiple instances
Recovery from deadlocks
Process termination
Resource preemption
Recap of lecture
January 27, 2016
Review of Lecture 28
Deadlock avoidance
Resource with single
instances
Resources with multiple
instances: Bankers algorithm
January 27, 2016
Deadlock Detection
Allow system to enter
deadlock state
Detection algorithm
Recovery scheme
January 27, 2016
January
27, 2016
Copyright
Virtual Univers
Resource-Allocation
Graph
Corresponding wait-for graph
ity of Pakistan
Multiple Instance of
Each 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.
January 27, 2016
Copyright Virtual Univers
ity of Pakistan
Multiple Instance of
Each Resource Type
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. Pj.
January 27, 2016
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
January Finish[i]
27, 2016
=
Copyright
Virtual Univers
true;
ity of Pakistan
Detection Algorithm
2. Find an index i such that both:
Detection Algorithm
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
deadlock state. Moreover, if
Finish[i] == false, then Pi is
deadlocked.
January 27, 2016
Copyright Virtual Univers
ity of Pakistan
Example of Detection
Algorithm
Consider the following system:
P = { P 0, P 1, P 2, P 3 , P 4 }
R = { A, B, C }
A: 7 instances
B: 2 instances
C:
January 27,
20166 instances
Copyright Virtual Univers
ity of Pakistan
Work
Process
A B C
A B C
P0
P1
P2
0 1 0
3 0 2
0 0 0
2 0 2
0 0 0
P3
P4
2 1 1
0 0 2
1 0 0
0 0 2
2 0 0
Finish
Sequence:
January 27, 2016
Copyright<>
Virtual Univers
ity of Pakistan
Work
Process
A B C
A B C
P0
P1
P2
0 1 0
0
0
0
1
0
0
3 0 2
0 0 0
2 0 2
0 0 0
P3
P4
2 1 1
0 0 2
1 0 0
0 0 2
2 0 0
Finish
Sequence:
P0>Univers
January 27, 2016
Copyright<Virtual
ity of Pakistan
Work
Process
A B C
A B C
P0
P1
P2
0 1 0
3 0 2
0 0 0
2 0 2
0 0 0
0
0
3
0
1
1
0
0
2
P3
P4
2 1 1
0 0 2
1 0 0
0 0 2
2 0 0
Finish
Sequence:
P0, Univers
P2>
January 27, 2016
Copyright<Virtual
ity of Pakistan
Work
Process
A B C
A B C
P0
P1
P2
0 1 0
3 0 2
0 0 0
2 0 2
0 0 0
0
0
3
0
1
1
0
0
2
P3
P4
2 1 1
0 0 2
1 0 0
0 0 2
2 0 0
Finish
Sequence:
P0,Univers
P2, P3>
January 27, 2016
Copyright<Virtual
ity of Pakistan
Work
Process
A B C
A B C
P0
P1
P2
0 1 0
3 0 2
0 0 0
2 0 2
0 0 0
0
0
3
0
1
1
0
0
2
P3
P4
2 1 1
0 0 2
1 0 0
0 0 2
5
5
2
2
3
5
2 0 0
Finish
Sequence:
P0,Univers
P2, P3, P4 >
January 27, 2016
Copyright<Virtual
ity of Pakistan
ity of Pakistan
Process Request
A B C
P0
P1
P2
0 0 0
2 0 2
0 0 1
P3
Copyright Virtual Univers P4
1 0 0
0 0 2
ity of Pakistan
Work
Process
A B C
A B C
P0
P1
P2
0 1 0
3 0 2
0 0 0
2 0 2
0 0 1
P3
P4
2 1 1
0 0 2
1 0 0
0 0 2
2 0 0
Finish
Sequence:
January 27, 2016
Copyright<>
Virtual Univers
ity of Pakistan
Work
Process
A B C
A B C
P0
P1
P2
0 1 0
0
0
0
1
0
0
3 0 2
0 0 0
2 0 2
0 0 1
P3
P4
2 1 1
0 0 2
1 0 0
0 0 2
2 0 0
Finish
Sequence:
P0>Univers
January 27, 2016
Copyright<Virtual
ity of Pakistan
Detection Algorithm
How often should the detection
algorithm be invoked?
Every time a request for
allocation cannot be granted
immediatelyexpensive but
process causing the deadlock
is identified, along with
processes
involved
January
27, 2016
Copyright
Virtual Universin deadlock
ity of Pakistan
Detection Algorithm
Periodically, or based on CPU
utilization
Arbitrarilythere may be many
cycles in the resource graph
and we would not be able to tell
which of the many deadlocked
processes caused the
deadlock.
January 27, 2016
Copyright Virtual Univers
ity of Pakistan
Recap of Lecture
Deadlock detection
Recovery from deadlock
Process termination
Resource preemption
Operating
Systems
Lecture 29
Syed Mansoor Sarwar
January 27, 2016