Professional Documents
Culture Documents
Chapter 5: Process Management
Chapter 5: Process Management
Chapter 5: Process Management
• Deadlock
– 7 Cases of Deadlock Process Synchronization
– Conditions for Deadlock
– Modeling Deadlocks
– Strategies for Handling
Deadlocks
– Avoidance
– Detection Deadlock Starvation
– Recovery Management
• Starvation Management
Understanding Operati 1
ng Systems
A Lack of Process Synchronization
Causes Deadlock or Starvation
• Deadlock (“deadly embrace”) -- a system-wide tangle of
resource requests that begins when 2+ jobs are put on hold.
Understanding Operati 2
ng Systems
Deadlock
• Deadlock is more serious than
indefinite postponement or
starvation because it affects
more than one job.
Understanding Operati 3
ng Systems
Seven Cases of Deadlocks
Understanding Operati 4
ng Systems
Case 1 : Deadlocks on File Requests
• If jobs can request and hold
files for duration of their
execution, deadlock can occur.
Understanding Operati 6
ng Systems
Case 3: Deadlocks in Dedicated
Device Allocation
1. P1 requests tape drive 1 and • Deadlock can occur when
gets it. there is a limited number
of dedicated devices.
2. P2 requests tape drive 2 and
gets it.
• E.g., printers, plotters or
3. P1 requests tape drive 2 but is tape drives.
blocked.
Understanding Operati 7
ng Systems
Case 4 : Deadlocks in Multiple
Device Allocation
• Deadlocks can happen
when several processes
request, and hold on to,
dedicated devices while
other processes act in a
similar manner.
Understanding Operati 8
ng Systems
Case 5 : Deadlocks in Spooling
Understanding Operati 9
ng Systems
Case 6 : Deadlocks in Disk Sharing
Understanding Operati 10
ng Systems
Case 7: Deadlocks in a Network
• A network that’s
congested (or filled large
% of its I/O buffer space)
can become deadlocked if
it doesn’t have protocols
to control flow of
messages through
network.
Understanding Operati 11
ng Systems
Four Conditions for Deadlock
• Mutual exclusion
• Resource holding
• No preemption
• Circular wait
Understanding Operati 12
ng Systems
• Mutual exclusion -- the act of allowing only one process
to have access to a dedicated resource.
Understanding Operati 14
ng Systems
Directed Graph Examples
R1 P1 R1
R2
R1 P1
Understanding Operati 15
ng Systems
Figure 5.8
R1 R1 R2 R2 R3 R3
P1 P1 P2 P2 P3 P3
Figure 5.9
R1 R2 R3 R1 R2 R3
P1 P2 P3 P1 P2 P3
Understanding Operati 16
ng Systems
P1 P3 Figure 5.11 (a)
P2
P1 P3
Understanding Operati 17
ng Systems
Strategies for Handling Deadlocks
Understanding Operati 18
ng Systems
Prevention of Deadlock
Understanding Operati 19
ng Systems
Prevention of Resource Holding
or No Preemption
• Resource holding can be avoided by forcing each job to
request, at creation time, every resource it will need to run
to completion.
– Significantly decreases degree of multiprogramming.
– Peripheral devices would be idle because allocated to a job even
though they wouldn't be used all the time.
Understanding Operati 20
ng Systems
Prevention of Circular Wait
Understanding Operati 21
ng Systems
Avoidance
Safe
Customer Loan amount Maximum credit Remaining credit
C1 0 4,000 4,000
C2 2,000 5,000 3,000
C3 4,000 8,000 4,000
Total loaned: $6,000
Total capital fund: $10,000
Unsafe
Customer Loan amount Maximum credit Remaining credit
C1 2,000 4,000 2,000
C2 3,000 5,000 2,000
C3 4,000 8,000 4,000
Total loaned: $9,000
Total capital fund: $10,000
Understanding Operati 24
ng Systems
Problems with Banker’s Algorithm
Understanding Operati 25
ng Systems
Detection
Understanding Operati 26
ng Systems
Reducing Directed Resource Graphs
Understanding Operati 27
ng Systems
R1 P2 P3 R1 P2 P3
P1 R2 R3 P1 R2 R3
Figure 5.12 (a)
Figure 5.12 (b)
R1 P2 P3 R1 P2 P3
P1 R2 R3 P1 R2 R3
Figure 5.12 (c)
Figure 5.12 (d)
Understanding Operati 28
ng Systems
Recovery
Understanding Operati 30
ng Systems
Select Victim with Least-Negative Effect
Understanding Operati 31
ng Systems
Starvation
Understanding Operati 32
ng Systems
Terminology
• avoidance • prevention
• circular wait • process synchronization
• deadlock • race
• deadly embrace • resource holding
• detection • safe state
• directed graphs • spooling
• locking • starvation
• mutual exclusion • unsafe state
• no preemption • victim
Understanding Operati 33
ng Systems