Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 9

Detection Algorithm

Example

Po P1 P2 P3 P4
Work= Available , Finish= F F F F F Po P1 P2 P3 P4
1. P0 Req.<=Work then , Work = work+ Allocation= 0,0,0+ 0,1,0= 0, 1, 0 T F F F F
Po P1 P2 P3 P4
2. p2 Req<Work then , Work = work+ Allocation= 0,1,0+3,0,3=3,1,3
T F T F F
3.. p3 Req<Work then , Work = work+ Allocation= 3,1,3+2,1,1=5,2,4 Po P1 P2 P3 P4
T F T T F
4. p4 Req<Work then , Work = work+ Allocation= 5,2,4+0,0,2=5,2,6
5. p1 Req<Work then , Work = work+ Allocation= 5,2,6+2,0,0=7,2,6 T F T T T
Safe Sequence < p0, p2, p3, p4, p1 > T T T T T
Example-II
Detection-Algorithm Usage
How often is a deadlock likely to occur?

1) If deadlocks occur frequently, then the detection algorithm


should be invoked frequently.

2) we can invoke the deadlock detection algorithm


every time a request for allocation cannot be
granted immediately.

3) Once per hour or whenever CPU utilization drops


below 40 percent
Recovery from Deadlock
When a detection algorithm determines that a
deadlock exists, several alternatives are available.

1) Deal with the deadlock manually


2) Recover from the deadlock automatically
• Abort one or more processes
• Preempt some resources
Recovery from Deadlock: Process
Termination
Recovery from Deadlock: Resource
Preemption!
To eliminate deadlocks using resource preemption, we successively
preempt some resources from processes and give these resources to
other processes until the deadlock cycle is broken.
Numerical

Ans- Available 0, 1, 2 Po P1 P2
Work= Available , Finish= F F F Po P1 P2
1. P1 Req.<Work then , Work = work+ Allocation= 0,1,2+ 2,0,1= 2, 1, 3 F T F
Po P1 P2
2. p0 Req<Work then , Work = work+ Allocation= 2,1,3+1,2,1=3,3,4
T T F
3.. p2 Req<Work then , Work = work+ Allocation= 3,3,4+2,2,1=5,5,5 Po P1 P2
T T T

Safe Sequence < p1, p0, p2>

You might also like