0% found this document useful (0 votes)
5 views33 pages

Ch6 Deadlock

Chapter 6 discusses deadlock in operating systems, defining it as a state where processes wait indefinitely for resources held by each other. It introduces resource-allocation graphs to visualize potential deadlocks and outlines methods for handling deadlock, including detection, avoidance, prevention, and recovery. The chapter emphasizes the importance of understanding the conditions that lead to deadlock and provides examples and algorithms, such as the Banker's Algorithm, for managing resources effectively.

Uploaded by

yosef jbara
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views33 pages

Ch6 Deadlock

Chapter 6 discusses deadlock in operating systems, defining it as a state where processes wait indefinitely for resources held by each other. It introduces resource-allocation graphs to visualize potential deadlocks and outlines methods for handling deadlock, including detection, avoidance, prevention, and recovery. The chapter emphasizes the importance of understanding the conditions that lead to deadlock and provides examples and algorithms, such as the Banker's Algorithm, for managing resources effectively.

Uploaded by

yosef jbara
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 33

Chapter 6: Deadlock

Operating System Concepts Essentials – 8th Edition Silberschatz, Galvin and Gagne ©2011
Module 6: Process Synchronization

 Needed Resources

 Definition

 Resource-Allocation Graph

 Conditions for Resource Deadlock

 Methods for Handling Deadlock

 Deadlock Detection

 Deadlock Avoidance - Bankers Algorithm

 Deadlock Prevention

 Deadlock Recovery

Operating System Concepts Essentials – 8th Edition 6.2 Silberschatz, Galvin and Gagne ©2011
Needed Resources

Operating System Concepts Essentials – 8th Edition 6.3 Silberschatz, Galvin and Gagne ©2011
Deadlock

Operating System Concepts Essentials – 8th Edition 6.4 Silberschatz, Galvin and Gagne ©2011
Deadlock definition
 Deadlock – A deadlocked state occurs when two or more processes are
waiting indefinitely for an event that can be caused by only one of the
waiting processes.

 Example
 System has 2 disk drives.
 P1 and P2 each hold one disk drive and each needs another one.

Operating System Concepts Essentials – 8th Edition 6.5 Silberschatz, Galvin and Gagne ©2011
Resource-Allocation Graph
A visual way to determine if a deadlock has, or may occur.

 The set of all the processes in the system denoted by P


and they can be P1, P2, …, Pn. [P = {P1, P2, …, Pn}]
A set of vertices (nodes) V

 The set of all resource types in the system denoted by R


and they can be R1, R2, …, Rm .[R = {R1, R2, …, Rm}]

 Request edge: directed edge Pi  Rj , which means


process Pi requests an instance of resource Rj .
A set of edges E
 Assignment edge : directed edge Rj  Pi ,which means
an instance of resource Rj is allocated to process Pi .

Operating System Concepts Essentials – 8th Edition 6.6 Silberschatz, Galvin and Gagne ©2011
Resource-Allocation Graph (Cont.)
 Process represented by a circle Pi

 Resource type represented by a square.


 dots represent number of instances of resource type
 Resource Type with 4 instances
Rj
Pi
 An arrow from the process to resource indicates
the process is requesting the resource. Pi requests instance of Rj
 Request points to square
Rj

 An arrow from resource to process indicates an instance Pi

of the resource has been allocated to the process. Pi is holding an instance of Rj


 Assignment comes from dot

Operating System Concepts Essentials – 8th Edition 6.7 Silberschatz, Galvin and Gagne ©2011
Resource-Allocation Graph (Cont.)

Operating System Concepts Essentials – 8th Edition 6.8 Silberschatz, Galvin and Gagne ©2011
Resource-Allocation Graph (Cont.)

Operating System Concepts Essentials – 8th Edition 6.9 Silberschatz, Galvin and Gagne ©2011
Conditions for Resource Deadlock

Operating System Concepts Essentials – 8th Edition 6.11 Silberschatz, Galvin and Gagne ©2011
Conditions for Resource Deadlock

Operating System Concepts Essentials – 8th Edition 6.12 Silberschatz, Galvin and Gagne ©2011
Conditions for Resource Deadlock

Operating System Concepts Essentials – 8th Edition 6.13 Silberschatz, Galvin and Gagne ©2011
Conditions for Resource Deadlock

Operating System Concepts Essentials – 8th Edition 6.14 Silberschatz, Galvin and Gagne ©2011
A Chanced Event

Operating System Concepts Essentials – 8th Edition 6.15 Silberschatz, Galvin and Gagne ©2011
A Chanced Event

Operating System Concepts Essentials – 8th Edition 6.16 Silberschatz, Galvin and Gagne ©2011
Multiple Resources

Operating System Concepts Essentials – 8th Edition 6.17 Silberschatz, Galvin and Gagne ©2011
Example of a Resource Allocation Graph

Operating System Concepts Essentials – 8th Edition 6.18 Silberschatz, Galvin and Gagne ©2011
Graph With A Cycle
 If the graph contains no cycles, then there are no deadlock processes.
 If there is a cycle, then there may be a deadlock:
a) If resource types have multiple instances, then deadlock MAY exist.
b) If each resource type has 1 instance, then deadlock has occurred.

R3 Assigned to P3

P2 Requests P3

Operating System Concepts Essentials – 8th Edition 6.19 Silberschatz, Galvin and Gagne ©2011
Resource Allocation Graph With A Cycle

Resource allocation graph Resource allocation graph


With a cycle but with a deadlock. with a cycle but no deadlock.

Operating System Concepts Essentials – 8th Edition 6.20 Silberschatz, Galvin and Gagne ©2011
Methods for Handling Deadlock
There are three strategies:
Ignore deadlocks and pretend that deadlocks never occur in the system.

Prevention: Prevent any one of the 4


conditions from happening.
Ensure deadlock never
occurs using either: Allow all deadlock conditions, but
Avoidance: calculate cycles about to happen
and stop dangerous operations.

Detection: Know a deadlock has occurred.


Allow deadlock to This requires using:
happen and then recover.
Recovery: Regain the resources.

Operating System Concepts Essentials – 8th Edition 6.21 Silberschatz, Galvin and Gagne ©2011
Deadlock Detection

Operating System Concepts Essentials – 8th Edition 6.22 Silberschatz, Galvin and Gagne ©2011
Deadlock Avoidance – Bankers Algorithm

Operating System Concepts Essentials – 8th Edition 6.23 Silberschatz, Galvin and Gagne ©2011
Deadlock Avoidance – Bankers Algorithm
 Consider a system with five processes [P1, P2, P3, P4, P5] and three resource types
[A, B, C]. Resource type A has 3 instances, Resource type B has 3 instances and
Resource type C has 2 instances. Suppose that at time Ts the following snapshot of the
system has been taken in the following table:

a) Find the total instances available for every


resource in the system .

b) Find the Need matrix for the system (the


nedded resources for every process).

c) Determine whether the system in a safe state.


If yes, provide the safe sequence.

1
Operating System Concepts Essentials – 8th Edition 6.26 Silberschatz, Galvin and Gagne ©2011
Operating System Concepts Essentials – 8th Edition 6.27 Silberschatz, Galvin and Gagne ©2011
Deadlock Avoidance – Bankers Algorithm
 Consider a system with five processes [P1, P2, P3, P4, P5] and three resources [A, B,
C]. The following table indicates the maximum requirements and current allocations for
these resources:

a) Find the total instances available for every


resource in the system.

b) Find the Need matrix for the system (the


nedded resources for every process).

a) Determine whether the system in a safe state.


If yes, provide the safe sequence.

2
Operating System Concepts Essentials – 8th Edition 6.28 Silberschatz, Galvin and Gagne ©2011
Operating System Concepts Essentials – 8th Edition 6.29 Silberschatz, Galvin and Gagne ©2011
Deadlock Avoidance – Bankers Algorithm
 Consider a system with five processes [P1, P2, P3, P4, P5] and four resource types
[A, B, C, D]. Resource type A has 8 instances, Resource type B has 5, Resource type C
has 9 instances and Resource type D has 8 instances. Suppose that at time Ts the
following snapshot of the system has been taken in the following table:

a) Find the total instances available for every


resource in the system .

b) Find the Need matrix for the system (the


nedded resources for every process).

c) Determine whether the system in a safe state.


If yes, provide the safe sequence.

9
Operating System Concepts Essentials – 8th Edition 6.30 Silberschatz, Galvin and Gagne ©2011
Operating System Concepts Essentials – 8th Edition 6.31 Silberschatz, Galvin and Gagne ©2011
Deadlock Prevention

Operating System Concepts Essentials – 8th Edition 6.32 Silberschatz, Galvin and Gagne ©2011
Deadlock Prevention

Operating System Concepts Essentials – 8th Edition 6.33 Silberschatz, Galvin and Gagne ©2011
Deadlock Recovery

Operating System Concepts Essentials – 8th Edition 6.34 Silberschatz, Galvin and Gagne ©2011
Deadlock Recovery

Operating System Concepts Essentials – 8th Edition 6.35 Silberschatz, Galvin and Gagne ©2011
Deadlock Recovery

Operating System Concepts Essentials – 8th Edition 6.36 Silberschatz, Galvin and Gagne ©2011

You might also like