CH8
CH8
Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018
Chapter Objectives
Operating System Concepts – 10th Edition 8.2 Silberschatz, Galvin and Gagne ©2018
System Model
Operating System Concepts – 10th Edition 8.3 Silberschatz, Galvin and Gagne ©2018
System Model
Operating System Concepts – 10th Edition 8.4 Silberschatz, Galvin and Gagne ©2018
Deadlock Characterization
Operating System Concepts – 10th Edition 8.5 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition 8.6 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition 8.7 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition 8.8 Silberschatz, Galvin and Gagne ©2018
Deadlock Characterization
Deadlock can arise if four conditions hold simultaneously:
Operating System Concepts – 10th Edition 8.9 Silberschatz, Galvin and Gagne ©2018
Resource-Allocation Graph (RAG)
A set of vertices V and a set of edges E:
V is partitioned into two types:
P = {P1, P2, …, Pn}, the set consisting of all the processes in the
system
Operating System Concepts – 10th Edition 8.10 Silberschatz, Galvin and Gagne ©2018
Resource-Allocation Graph (Cont.)
Process
Pi requests instance of Rj
Pi
Rj
Pi is holding an instance of Rj
Pi
Rj
Operating System Concepts – 10th Edition 8.11 Silberschatz, Galvin and Gagne ©2018
Example of a RAG
Operating System Concepts – 10th Edition 8.12 Silberschatz, Galvin and Gagne ©2018
Example of a RAG with Deadlock
Operating System Concepts – 10th Edition 8.13 Silberschatz, Galvin and Gagne ©2018
Example of a RAG without Deadlock
Operating System Concepts – 10th Edition 8.14 Silberschatz, Galvin and Gagne ©2018
Basic Facts
Operating System Concepts – 10th Edition 8.15 Silberschatz, Galvin and Gagne ©2018
Methods for Handling Deadlocks
Operating System Concepts – 10th Edition 8.16 Silberschatz, Galvin and Gagne ©2018
Methods for Handling Deadlocks
Ignore the problem and pretend that deadlocks never occur in the
system; used by most operating systems, including UNIX
Operating System Concepts – 10th Edition 8.17 Silberschatz, Galvin and Gagne ©2018
Deadlock Prevention
Operating System Concepts – 10th Edition 8.18 Silberschatz, Galvin and Gagne ©2018
Deadlock Prevention
Restrain the ways request can be made
Operating System Concepts – 10th Edition 8.19 Silberschatz, Galvin and Gagne ©2018
Deadlock Prevention (Cont.)
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
Process will be restarted only when it can regain its old resources,
as well as the new ones that it is requesting
Operating System Concepts – 10th Edition 8.20 Silberschatz, Galvin and Gagne ©2018
Deadlock Avoidance
Operating System Concepts – 10th Edition 8.21 Silberschatz, Galvin and Gagne ©2018
Deadlock Avoidance
Requires that the system has some additional a priori information
available
Simplest and most useful model requires that each process
declares the maximum number of resources of each type that it
may need
Operating System Concepts – 10th Edition 8.22 Silberschatz, Galvin and Gagne ©2018
Safe State
That is:
If Pi resource needs are not immediately available, then Pi can wait
until all Pj have finished
When Pj is finished, Pi can obtain needed resources, execute,
return allocated resources, and terminate
When Pi terminates, Pi +1 can obtain its needed resources, and so
on
Operating System Concepts – 10th Edition 8.23 Silberschatz, Galvin and Gagne ©2018
Basic Facts
Operating System Concepts – 10th Edition 8.24 Silberschatz, Galvin and Gagne ©2018
Safe, Unsafe, Deadlock State
Operating System Concepts – 10th Edition 8.25 Silberschatz, Galvin and Gagne ©2018
Avoidance Algorithms
Operating System Concepts – 10th Edition 8.26 Silberschatz, Galvin and Gagne ©2018
Resource-Allocation Graph Scheme
Claim edge Pi Rj indicates that process Pi may request resource Rj;
represented by a dashed line
Operating System Concepts – 10th Edition 8.27 Silberschatz, Galvin and Gagne ©2018
RAG
Operating System Concepts – 10th Edition 8.28 Silberschatz, Galvin and Gagne ©2018
Unsafe State
Operating System Concepts – 10th Edition 8.29 Silberschatz, Galvin and Gagne ©2018
RAG Algorithm
Operating System Concepts – 10th Edition 8.30 Silberschatz, Galvin and Gagne ©2018
Banker’s Algorithm
Multiple instances
Operating System Concepts – 10th Edition 8.31 Silberschatz, Galvin and Gagne ©2018
Deadlock Detection and Recovery
Operating System Concepts – 10th Edition 8.32 Silberschatz, Galvin and Gagne ©2018
Deadlock Detection and Recovery
Detection algorithm
Recovery scheme
Operating System Concepts – 10th Edition 8.33 Silberschatz, Galvin and Gagne ©2018
Single Instance of Each Resource Type
Operating System Concepts – 10th Edition 8.34 Silberschatz, Galvin and Gagne ©2018
Resource-Allocation Graph and Wait-for Graph
Operating System Concepts – 10th Edition 8.35 Silberschatz, Galvin and Gagne ©2018
Several Instances of a Resource Type
Operating System Concepts – 10th Edition 8.36 Silberschatz, Galvin and Gagne ©2018
Detection Algorithm
Operating System Concepts – 10th Edition 8.37 Silberschatz, Galvin and Gagne ©2018
Detection Algorithm (Cont.)
3. Work = Work + Allocationi
Finish[i] = true
go to step 2
Operating System Concepts – 10th Edition 8.38 Silberschatz, Galvin and Gagne ©2018
Detection-Algorithm Usage
When, and how often, to invoke depends on:
How often a deadlock is likely to occur?
How many processes will need to be rolled back?
one for each disjoint cycle
Operating System Concepts – 10th Edition 8.39 Silberschatz, Galvin and Gagne ©2018
Recovery from Deadlock: Process Termination
Operating System Concepts – 10th Edition 8.40 Silberschatz, Galvin and Gagne ©2018
Recovery from Deadlock: Resource Preemption
Rollback – return to some safe state, restart process for that state
Operating System Concepts – 10th Edition 8.41 Silberschatz, Galvin and Gagne ©2018
End of Chapter 8
Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018