SlideShare a Scribd company logo
Amrita
School
of
Engineering,
Bangalore
Ms. Harika Pudugosula
Lecturer
Department of Electronics & Communication Engineering
• System Model
• Deadlock Characterization
• Methods for Handling Deadlocks
• Deadlock Prevention
• Deadlock Avoidance
• Deadlock Detection
• Recovery from Deadlock
2
Deadlock Detection
• If a system does not employ either a deadlock-prevention or a deadlock avoidance
algorithm, then a deadlock situation may occur
• In this environment, the system may provide -
• An algorithm that examines the state of the system to determine whether a
deadlock has occurred
• An algorithm to recover from the deadlock
• Two requirements as they pertain to systems with only a single instance of each
resource type, systems with several instances of each resource type
• Includes not only the run-time costs of maintaining the necessary information and
executing the detection algorithm but also the potential losses inherent in
recovering from a deadlock
3
Single Instance of Each Resource Type
• If all resources have only a single instance, then we can define a deadlock detection
algorithm that uses a variant of the resource-allocation graph - Wait-for graph
• Graph obtained from the resource-allocation graph by removing the resource nodes
and collapsing the appropriate edge
• An edge from Pi to Pj in a wait-for graph implies that process Pi is waiting for
process Pj to release a resource that Pi needs
• An edge Pi → Pj exists in a wait-for graph if and only if the corresponding resource
allocation graph contains two edges Pi → Rq and Rq → Pj for some resource Rq
• A deadlock exists in the system if and only if the wait-for graph contains a cycle
• To detect deadlocks, the system needs to maintain the wait-for graph and periodically
invoke an algorithm that searches for a cycle in the graph
• An algorithm to detect a cycle in a graph requires an order of n2 operations, where n
is the number of vertices in the graph
4
Single Instance of Each Resource Type
5
fig a : Resource-Allocation Graph fig b: Corresponding wait-for graph
Several Instances of a Resource Type
• The wait-for graph scheme is not applicable to a resource-allocation system with
multiple instances of each resource type
• The algorithm employs several time-varying data structures
• Available - A vector of length m indicates the number of available resources of
each type
• Allocation - An n × m matrix defines the number of resources of each type
currently allocated to each process
• Request - An n × m matrix indicates the current request of each process. If
Request[i][j] equals k, then process Pi is requesting k more instances of resource
type Rj
• Algorithm requires an order of O(m x n2) operations to detect whether the system is
in deadlocked state
6
Several Instances of a Resource Type - Deadlock Detection Algorithm
7
1. Let Work and Finish be vectors of length m and n, respectively Initialize:
(a) Work = Available
(b)For i = 1,2, …, n, if Allocationi 0, then
Finish[i] = false; otherwise, Finish[i] = true
2. Find an index i such that both:
(a)Finish[i] == false
(b) Requesti <= Work
If no such i exists, go to step 4
3. Work = Work + Allocationi
Finish[i] = true
go to step 2
4. If Finish[i] == false, for some i, 0<= i <=n, then the system is in deadlock state.
Moreover, if Finish[i] == false, then Pi is deadlocked
Example - Deadlock Detection Algorithm
8
• Consider a system with five processes P0 through P4 and three resource types A, B,
and C. Resource type A has seven instances, resource type B has two instances, and
resource type C has six instances. Suppose that, at time T0, we have the following
resource-allocation state -
• System is not in a deadlocked state
Indeed, if we execute our algorithm,
we will find that the sequence
<P0, P2, P3, P1, P4> results in
Finish[i] == true for all i
• A= 7-7=0
• B=2-2=0
• C=6-6=0
• P0
Request<=work
0 0 0 <= 0 0 0 true
Work=work+allocation 0 0 0+0 1 0= 0 1 0 finish[0]=true
P0-false P1-false P2-false P3-false P4-false
0- true
9
• P1
Request <=work
2 0 2 <= 0 1 0 false p1 has to wait
• P2
Request <=work
0 0 0 <= 0 1 0 true
work=work+allocation 0 1 0 + 3 0 3=3 1 3 finish[2]=true
• P3
Request <=work
1 0 0 <= 3 1 3 true
Work= work +allocation 3 1 3 + 2 1 1= 5 2 4 finish [3]= true
• P4
Request <=work
0 0 2 < = 5 2 4 true
Work=work+ allocation 5 2 4 + 0 0 2= 5 2 6 finish[4]=true
10
• P1
Request <= work
2 0 2 <= 5 2 6
work= work + allocation 5 2 6+2 0 0= 7 2 6
• Safe sequence <p0,p2,p3,p4,p1>
11
Example - Deadlock Detection Algorithm
12
• Consider a system with five processes P0 through P4 and three resource types A, B,
and C. Resource type A has seven instances, resource type B has two instances, and
resource type C has six instances. Suppose that, at time T0, we have the following
resource-allocation state -
• System is in a deadlocked state
ALthough, reclaiming the resources
held by process P0, the number of
available resources is not sufficient
to fulfill the requests of the other
processes.
• Thus, a deadlock exists, consisting
of processes P1, P2, P3, and P4
Detection - Algorithm Usage
13
• When, and how often, to invoke depends on:
• How often a deadlock is likely to occur?
• How many processes will be affected by deadlock when it happens?
• We can invoke the deadlock-detection algorithm every time a request for allocation
cannot be granted immediately
• Invoking the deadlock-detection algorithm for every resource request will incur
considerable overhead in computation time
• A less expensive alternative is simply to invoke the algorithm at defined intervals—
for example, once per hour or whenever CPU utilization drops below 40 percent. (A
deadlock eventually cripples system throughput and causes CPU utilization to drop)
• If the detection algorithm is invoked at arbitrary points in time, the resource graph
may contain many cycles. In this case, we generally cannot tell which of the many
deadlocked processes “caused” the deadlock.
Recovery from Deadlock
• When a detection algorithm determines that a deadlock exists, several alternatives
are available.
1. Inform the operator that a deadlock has occurred and to let the operator deal
with the deadlock manually
2. Let the system recover from the deadlock automatically
• Two options for breaking a deadlock -
• Process termination
a. abort all deadlocked process
Example - Assume 10 process in that 3 process suffer deadlock they have to be
aborted
P0=95% P1=90%, P2=88% execution completed
it has used CPU time, memory, I/O devices
it is expensive approach
14
b. To abort one process at a time until deadlock cycle is eliminated i.e circular
wait
- p0,p1,p2 suffer from deadlock
- abort p0 and apply deadlock detection algorithm to find cycle is
eliminated
- similarly apply for p1,p2
• In which order should we choose to abort the process from many processes
1. Priority of the process
2. How long process has computed, and how much longer to completion
3. Resources the process has used
4. Resources process needs to complete
5. How many processes will need to be terminated
6. Is process interactive or batch?
15
Recovery from Deadlock
Recovery from Deadlock
• Two options for breaking a 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
• If preemption is required to deal with deadlocks, then three issues need to
be addressed
1. Selecting a victim – i.e., Which resources and which processes are to be
preempted?
• As in process termination, we must determine the order of preemption to
minimize cost
• Cost factors may include such parameters as the number of resources a
deadlocked process is holding and the amount of time the process has thus far
consumed
16
Recovery from Deadlock
2. Rollback - If we pre-empt a resource from a process, what should be done with that
process?
• Clearly, it cannot continue with its normal execution; it is missing some needed
resource. We must roll back the process to some safe state and restart it from
that state
3. Starvation -
• How do we ensure that starvation will not occur? That is, how can we guarantee
that resources will not always be pre-empted from the same process?
• Ensure that a process can be picked as a victim only a (small) finite number of
times
17
18
References
1. Silberscatnz and Galvin, “Operating System Concepts,” Ninth Edition,
John Wiley and Sons, 2012.
19
Thank you

More Related Content

PPTX
Deadlock - An Operating System Concept.pptx
viceprincipalbfc
 
PPTX
Deadlock
Abhinaw Rai
 
PDF
deadlock.pdfdkfglknalkdnglqgjlejgooooo;o
baijusurya7
 
PPTX
osvzjsjjdndnnssnnsnsndndndnndeadlock.pptx
Bhaskar271887
 
PPT
Ch07 deadlocks
Nazir Ahmed
 
PPTX
Gp1242 007 oer ppt
Nivedita Kasturi
 
PPTX
Module 3 Deadlocks.pptx
shreesha16
 
PPTX
Deadlock Detection.pptx
infomerlin
 
Deadlock - An Operating System Concept.pptx
viceprincipalbfc
 
Deadlock
Abhinaw Rai
 
deadlock.pdfdkfglknalkdnglqgjlejgooooo;o
baijusurya7
 
osvzjsjjdndnnssnnsnsndndndnndeadlock.pptx
Bhaskar271887
 
Ch07 deadlocks
Nazir Ahmed
 
Gp1242 007 oer ppt
Nivedita Kasturi
 
Module 3 Deadlocks.pptx
shreesha16
 
Deadlock Detection.pptx
infomerlin
 

Similar to Deadlocks Part- III.pdf (20)

PPT
Deadlock
Mayuri Verma
 
PDF
Deadlock detection
A. S. M. Shafi
 
PPT
Operating System
Subhasis Dash
 
PPTX
hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
HenryWongChengyong1
 
PPT
14th November - Deadlock Prevention, Avoidance.ppt
Unknown664473
 
PPTX
Algorithm 4Chapter Four- Deadlock (5).pptx
jamsibro140
 
PDF
Chapter 5(five).pdf
amanuel236786
 
PDF
deadlocks for Engenerring for he purpose
adityaarya357060
 
PPT
Mca ii os u-3 dead lock & io systems
Rai University
 
PPTX
6. Deadlock_1640227623705.pptx
shrijanasharma3
 
PDF
Ch7 deadlocks
Welly Dian Astika
 
PPT
A ppt on deadlock in operating systems for the better explanation
AkashPundir2
 
PPTX
Deadlock in Operating SystemSystem Model Deadlock Characterization
SABITHARASSISTANTPRO
 
PPTX
Deadlock in Operating system concept, Types of Deadlock
SABITHARASSISTANTPRO
 
PPT
Mch7 deadlock
wahab13
 
PDF
9 deadlock
GRajendra
 
PPT
deadlock part5 unit 2.ppt
054sreeharshithvajin
 
PDF
Deadlock in Distributed Systems
Pritom Saha Akash
 
PPTX
Deadlock
Mahershi ACT
 
PDF
Deadlock Avoidance - OS
MsAnita2
 
Deadlock
Mayuri Verma
 
Deadlock detection
A. S. M. Shafi
 
Operating System
Subhasis Dash
 
hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
HenryWongChengyong1
 
14th November - Deadlock Prevention, Avoidance.ppt
Unknown664473
 
Algorithm 4Chapter Four- Deadlock (5).pptx
jamsibro140
 
Chapter 5(five).pdf
amanuel236786
 
deadlocks for Engenerring for he purpose
adityaarya357060
 
Mca ii os u-3 dead lock & io systems
Rai University
 
6. Deadlock_1640227623705.pptx
shrijanasharma3
 
Ch7 deadlocks
Welly Dian Astika
 
A ppt on deadlock in operating systems for the better explanation
AkashPundir2
 
Deadlock in Operating SystemSystem Model Deadlock Characterization
SABITHARASSISTANTPRO
 
Deadlock in Operating system concept, Types of Deadlock
SABITHARASSISTANTPRO
 
Mch7 deadlock
wahab13
 
9 deadlock
GRajendra
 
deadlock part5 unit 2.ppt
054sreeharshithvajin
 
Deadlock in Distributed Systems
Pritom Saha Akash
 
Deadlock
Mahershi ACT
 
Deadlock Avoidance - OS
MsAnita2
 
Ad

More from Harika Pudugosula (20)

PPTX
Artificial Neural Networks_Part-2.pptx
Harika Pudugosula
 
PPTX
Artificial Neural Networks_Part-1.pptx
Harika Pudugosula
 
PPTX
Introduction.pptx
Harika Pudugosula
 
PDF
CPU Scheduling Part-III.pdf
Harika Pudugosula
 
PDF
CPU Scheduling Part-II.pdf
Harika Pudugosula
 
PDF
CPU Scheduling Part-I.pdf
Harika Pudugosula
 
PDF
Multithreaded Programming Part- III.pdf
Harika Pudugosula
 
PDF
Multithreaded Programming Part- II.pdf
Harika Pudugosula
 
PDF
Multithreaded Programming Part- I.pdf
Harika Pudugosula
 
PDF
Deadlocks Part- II.pdf
Harika Pudugosula
 
PDF
Deadlocks Part- I.pdf
Harika Pudugosula
 
PDF
Memory Management Strategies - IV.pdf
Harika Pudugosula
 
PDF
Memory Management Strategies - III.pdf
Harika Pudugosula
 
PDF
Memory Management Strategies - II.pdf
Harika Pudugosula
 
PDF
Memory Management Strategies - I.pdf
Harika Pudugosula
 
PDF
Virtual Memory Management Part - II.pdf
Harika Pudugosula
 
PDF
Virtual Memory Management Part - I.pdf
Harika Pudugosula
 
PDF
Operating System Structure Part-II.pdf
Harika Pudugosula
 
PDF
Operating System Structure Part-I.pdf
Harika Pudugosula
 
PDF
Lecture-4_Process Management.pdf
Harika Pudugosula
 
Artificial Neural Networks_Part-2.pptx
Harika Pudugosula
 
Artificial Neural Networks_Part-1.pptx
Harika Pudugosula
 
Introduction.pptx
Harika Pudugosula
 
CPU Scheduling Part-III.pdf
Harika Pudugosula
 
CPU Scheduling Part-II.pdf
Harika Pudugosula
 
CPU Scheduling Part-I.pdf
Harika Pudugosula
 
Multithreaded Programming Part- III.pdf
Harika Pudugosula
 
Multithreaded Programming Part- II.pdf
Harika Pudugosula
 
Multithreaded Programming Part- I.pdf
Harika Pudugosula
 
Deadlocks Part- II.pdf
Harika Pudugosula
 
Deadlocks Part- I.pdf
Harika Pudugosula
 
Memory Management Strategies - IV.pdf
Harika Pudugosula
 
Memory Management Strategies - III.pdf
Harika Pudugosula
 
Memory Management Strategies - II.pdf
Harika Pudugosula
 
Memory Management Strategies - I.pdf
Harika Pudugosula
 
Virtual Memory Management Part - II.pdf
Harika Pudugosula
 
Virtual Memory Management Part - I.pdf
Harika Pudugosula
 
Operating System Structure Part-II.pdf
Harika Pudugosula
 
Operating System Structure Part-I.pdf
Harika Pudugosula
 
Lecture-4_Process Management.pdf
Harika Pudugosula
 
Ad

Recently uploaded (20)

PPTX
Inventory management chapter in automation and robotics.
atisht0104
 
PDF
Chad Ayach - A Versatile Aerospace Professional
Chad Ayach
 
PDF
top-5-use-cases-for-splunk-security-analytics.pdf
yaghutialireza
 
PDF
FLEX-LNG-Company-Presentation-Nov-2017.pdf
jbloggzs
 
PPTX
MSME 4.0 Template idea hackathon pdf to understand
alaudeenaarish
 
PDF
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
PPTX
FUNDAMENTALS OF ELECTRIC VEHICLES UNIT-1
MikkiliSuresh
 
PPT
1. SYSTEMS, ROLES, AND DEVELOPMENT METHODOLOGIES.ppt
zilow058
 
PDF
Machine Learning All topics Covers In This Single Slides
AmritTiwari19
 
PDF
settlement FOR FOUNDATION ENGINEERS.pdf
Endalkazene
 
PDF
Natural_Language_processing_Unit_I_notes.pdf
sanguleumeshit
 
PPTX
Tunnel Ventilation System in Kanpur Metro
220105053
 
PDF
Zero carbon Building Design Guidelines V4
BassemOsman1
 
PDF
Advanced LangChain & RAG: Building a Financial AI Assistant with Real-Time Data
Soufiane Sejjari
 
PPTX
sunil mishra pptmmmmmmmmmmmmmmmmmmmmmmmmm
singhamit111
 
PDF
2010_Book_EnvironmentalBioengineering (1).pdf
EmilianoRodriguezTll
 
PDF
Biodegradable Plastics: Innovations and Market Potential (www.kiu.ac.ug)
publication11
 
PDF
LEAP-1B presedntation xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
hatem173148
 
PDF
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
PDF
Introduction to Ship Engine Room Systems.pdf
Mahmoud Moghtaderi
 
Inventory management chapter in automation and robotics.
atisht0104
 
Chad Ayach - A Versatile Aerospace Professional
Chad Ayach
 
top-5-use-cases-for-splunk-security-analytics.pdf
yaghutialireza
 
FLEX-LNG-Company-Presentation-Nov-2017.pdf
jbloggzs
 
MSME 4.0 Template idea hackathon pdf to understand
alaudeenaarish
 
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
FUNDAMENTALS OF ELECTRIC VEHICLES UNIT-1
MikkiliSuresh
 
1. SYSTEMS, ROLES, AND DEVELOPMENT METHODOLOGIES.ppt
zilow058
 
Machine Learning All topics Covers In This Single Slides
AmritTiwari19
 
settlement FOR FOUNDATION ENGINEERS.pdf
Endalkazene
 
Natural_Language_processing_Unit_I_notes.pdf
sanguleumeshit
 
Tunnel Ventilation System in Kanpur Metro
220105053
 
Zero carbon Building Design Guidelines V4
BassemOsman1
 
Advanced LangChain & RAG: Building a Financial AI Assistant with Real-Time Data
Soufiane Sejjari
 
sunil mishra pptmmmmmmmmmmmmmmmmmmmmmmmmm
singhamit111
 
2010_Book_EnvironmentalBioengineering (1).pdf
EmilianoRodriguezTll
 
Biodegradable Plastics: Innovations and Market Potential (www.kiu.ac.ug)
publication11
 
LEAP-1B presedntation xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
hatem173148
 
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
Introduction to Ship Engine Room Systems.pdf
Mahmoud Moghtaderi
 

Deadlocks Part- III.pdf

  • 2. • System Model • Deadlock Characterization • Methods for Handling Deadlocks • Deadlock Prevention • Deadlock Avoidance • Deadlock Detection • Recovery from Deadlock 2
  • 3. Deadlock Detection • If a system does not employ either a deadlock-prevention or a deadlock avoidance algorithm, then a deadlock situation may occur • In this environment, the system may provide - • An algorithm that examines the state of the system to determine whether a deadlock has occurred • An algorithm to recover from the deadlock • Two requirements as they pertain to systems with only a single instance of each resource type, systems with several instances of each resource type • Includes not only the run-time costs of maintaining the necessary information and executing the detection algorithm but also the potential losses inherent in recovering from a deadlock 3
  • 4. Single Instance of Each Resource Type • If all resources have only a single instance, then we can define a deadlock detection algorithm that uses a variant of the resource-allocation graph - Wait-for graph • Graph obtained from the resource-allocation graph by removing the resource nodes and collapsing the appropriate edge • An edge from Pi to Pj in a wait-for graph implies that process Pi is waiting for process Pj to release a resource that Pi needs • An edge Pi → Pj exists in a wait-for graph if and only if the corresponding resource allocation graph contains two edges Pi → Rq and Rq → Pj for some resource Rq • A deadlock exists in the system if and only if the wait-for graph contains a cycle • To detect deadlocks, the system needs to maintain the wait-for graph and periodically invoke an algorithm that searches for a cycle in the graph • An algorithm to detect a cycle in a graph requires an order of n2 operations, where n is the number of vertices in the graph 4
  • 5. Single Instance of Each Resource Type 5 fig a : Resource-Allocation Graph fig b: Corresponding wait-for graph
  • 6. Several Instances of a Resource Type • The wait-for graph scheme is not applicable to a resource-allocation system with multiple instances of each resource type • The algorithm employs several time-varying data structures • Available - A vector of length m indicates the number of available resources of each type • Allocation - An n × m matrix defines the number of resources of each type currently allocated to each process • Request - An n × m matrix indicates the current request of each process. If Request[i][j] equals k, then process Pi is requesting k more instances of resource type Rj • Algorithm requires an order of O(m x n2) operations to detect whether the system is in deadlocked state 6
  • 7. Several Instances of a Resource Type - Deadlock Detection Algorithm 7 1. Let Work and Finish be vectors of length m and n, respectively Initialize: (a) Work = Available (b)For i = 1,2, …, n, if Allocationi 0, then Finish[i] = false; otherwise, Finish[i] = true 2. Find an index i such that both: (a)Finish[i] == false (b) Requesti <= Work If no such i exists, go to step 4 3. Work = Work + Allocationi Finish[i] = true go to step 2 4. If Finish[i] == false, for some i, 0<= i <=n, then the system is in deadlock state. Moreover, if Finish[i] == false, then Pi is deadlocked
  • 8. Example - Deadlock Detection Algorithm 8 • Consider a system with five processes P0 through P4 and three resource types A, B, and C. Resource type A has seven instances, resource type B has two instances, and resource type C has six instances. Suppose that, at time T0, we have the following resource-allocation state - • System is not in a deadlocked state Indeed, if we execute our algorithm, we will find that the sequence <P0, P2, P3, P1, P4> results in Finish[i] == true for all i
  • 9. • A= 7-7=0 • B=2-2=0 • C=6-6=0 • P0 Request<=work 0 0 0 <= 0 0 0 true Work=work+allocation 0 0 0+0 1 0= 0 1 0 finish[0]=true P0-false P1-false P2-false P3-false P4-false 0- true 9
  • 10. • P1 Request <=work 2 0 2 <= 0 1 0 false p1 has to wait • P2 Request <=work 0 0 0 <= 0 1 0 true work=work+allocation 0 1 0 + 3 0 3=3 1 3 finish[2]=true • P3 Request <=work 1 0 0 <= 3 1 3 true Work= work +allocation 3 1 3 + 2 1 1= 5 2 4 finish [3]= true • P4 Request <=work 0 0 2 < = 5 2 4 true Work=work+ allocation 5 2 4 + 0 0 2= 5 2 6 finish[4]=true 10
  • 11. • P1 Request <= work 2 0 2 <= 5 2 6 work= work + allocation 5 2 6+2 0 0= 7 2 6 • Safe sequence <p0,p2,p3,p4,p1> 11
  • 12. Example - Deadlock Detection Algorithm 12 • Consider a system with five processes P0 through P4 and three resource types A, B, and C. Resource type A has seven instances, resource type B has two instances, and resource type C has six instances. Suppose that, at time T0, we have the following resource-allocation state - • System is in a deadlocked state ALthough, reclaiming the resources held by process P0, the number of available resources is not sufficient to fulfill the requests of the other processes. • Thus, a deadlock exists, consisting of processes P1, P2, P3, and P4
  • 13. Detection - Algorithm Usage 13 • When, and how often, to invoke depends on: • How often a deadlock is likely to occur? • How many processes will be affected by deadlock when it happens? • We can invoke the deadlock-detection algorithm every time a request for allocation cannot be granted immediately • Invoking the deadlock-detection algorithm for every resource request will incur considerable overhead in computation time • A less expensive alternative is simply to invoke the algorithm at defined intervals— for example, once per hour or whenever CPU utilization drops below 40 percent. (A deadlock eventually cripples system throughput and causes CPU utilization to drop) • If the detection algorithm is invoked at arbitrary points in time, the resource graph may contain many cycles. In this case, we generally cannot tell which of the many deadlocked processes “caused” the deadlock.
  • 14. Recovery from Deadlock • When a detection algorithm determines that a deadlock exists, several alternatives are available. 1. Inform the operator that a deadlock has occurred and to let the operator deal with the deadlock manually 2. Let the system recover from the deadlock automatically • Two options for breaking a deadlock - • Process termination a. abort all deadlocked process Example - Assume 10 process in that 3 process suffer deadlock they have to be aborted P0=95% P1=90%, P2=88% execution completed it has used CPU time, memory, I/O devices it is expensive approach 14
  • 15. b. To abort one process at a time until deadlock cycle is eliminated i.e circular wait - p0,p1,p2 suffer from deadlock - abort p0 and apply deadlock detection algorithm to find cycle is eliminated - similarly apply for p1,p2 • In which order should we choose to abort the process from many processes 1. Priority of the process 2. How long process has computed, and how much longer to completion 3. Resources the process has used 4. Resources process needs to complete 5. How many processes will need to be terminated 6. Is process interactive or batch? 15 Recovery from Deadlock
  • 16. Recovery from Deadlock • Two options for breaking a 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 • If preemption is required to deal with deadlocks, then three issues need to be addressed 1. Selecting a victim – i.e., Which resources and which processes are to be preempted? • As in process termination, we must determine the order of preemption to minimize cost • Cost factors may include such parameters as the number of resources a deadlocked process is holding and the amount of time the process has thus far consumed 16
  • 17. Recovery from Deadlock 2. Rollback - If we pre-empt a resource from a process, what should be done with that process? • Clearly, it cannot continue with its normal execution; it is missing some needed resource. We must roll back the process to some safe state and restart it from that state 3. Starvation - • How do we ensure that starvation will not occur? That is, how can we guarantee that resources will not always be pre-empted from the same process? • Ensure that a process can be picked as a victim only a (small) finite number of times 17
  • 18. 18 References 1. Silberscatnz and Galvin, “Operating System Concepts,” Ninth Edition, John Wiley and Sons, 2012.