SlideShare a Scribd company logo
1 of 38
DEADLOCK
AVOIDANCE,PREVENTION,DETECTION,IGNORANCE
What??
• Two or more processes are waiting for an event which is never going to occur.
• A process requests resources; if the resources are not available at that time, the
process enters a waiting state. Sometimes, a waiting process is never again able to
change state, because the resources it has requested are held by other waiting
processes. This situation is called a deadlock.
System Model
• A process may utilize a resource in only the following sequence:
1. Request: The process requests the resource. If the request cannot be granted
immediately (for example, if the resource is being used by another process),
then the requesting process must wait until it can acquire the resource.
2. Use: The process can operate on the resource (for example, if the resource is a
printer, the process can print on the printer).
3. Release: The process releases the resource.
Why??
• Due to four conditions that hold simultaneously in a system.
1. Mutual exclusion.
2. Hold and wait
3. No pre-emption
4. Circular wait
Resource-Allocation Graph
• Deadlocks can be described more precisely in terms of a directed graph called a
system resource-allocation graph.
• This graph consists of a set of vertices V and a set of edges E.
a) The set of vertices V is partitioned into two different types of nodes:
P = {P1, P2, ..., Pn}, the set consisting of all the active processes in the system,
and
R = {R1, R2, ..., Rm}, the set consisting of all resource types in the system.
Contd.
b) A directed edge from process Pi to resource type Rj is denoted by Pi → Rj ; it
signifies that process Pi has requested an instance of resource type Rj and is
currently waiting for that resource.
A directed edge from resource type Rj to process Pi is denoted by Rj → Pi ; it
signifies that an instance of resource type Rj has been allocated to process Pi .
A directed edge Pi → Rj is called a request edge; a directed edge Rj → Pi is called
an assignment edge.
Contd.
• Pictorially, we represent each process Pi as a circle and each resource type Rj as a
rectangle. Since resource type Rj may have more than one instance, we represent
each such instance as a dot within the rectangle.
• If the graph contains no cycles, then no process in the system is deadlocked. If the
graph does contain a cycle, then a deadlock may exist.
Example
The sets P, R, and E:
P = {P1, P2, P3}
R = {R1, R2, R3, R4}
E = {P1 → R1, P2 → R3, R1 → P2, R2 → P2, R2 → P1, R3 → P3}
Resource instances:
• One instance of resource type R1
• Two instances of resource type R2
• One instance of resource type R3
• Three instances of resource type R4
Process states:
• Process P1 is holding an instance of resource type R2 and is waiting for an instance
of resource type R1.
• Process P2 is holding an instance of R1 and an instance of R2 and is waiting for an
instance of R3.
• Process P3 is holding an instance of R3.
Contd.
• If the cycle involves only a set of resource types, each of which has only a single
instance, then a deadlock has occurred. Each process involved in the cycle is
deadlocked. In this case, a cycle in the graph is both a necessary and a sufficient
condition for the existence of deadlock.
• If each resource type has several instances, then a cycle does not necessarily
imply that a deadlock has occurred. In this case, a cycle in the graph is a necessary
but not a sufficient condition for the existence of deadlock.
Contd.
Resource-allocation graph with a cycle but no deadlock.
Resource-allocation graph with a deadlock.
Contd.
• if a resource-allocation graph does not have a cycle, then the system is not in a
deadlocked state. If there is a cycle, then the system may or may not be in a
deadlocked state.
How??
• Can deal with the deadlock problem in one of three ways:
1. We can use a protocol to prevent or avoid deadlocks, ensuring that the system
will never enter a deadlocked state.
2. We can allow the system to enter a deadlocked state, detect it, and recover.
3. We can ignore the problem altogether and pretend that deadlocks never occur in
the system.
Contd.
• Deadlock prevention provides a set of methods to ensure that at least one of the
necessary conditions cannot hold. These methods prevent deadlocks by
constraining how requests for resources can be made.
• Deadlock avoidance requires that the operating system be given additional
information in advance concerning which resources a process will request and use
during its lifetime. With this additional knowledge, the operating system can
decide for each request whether or not the process should wait.
Contd.
• If a system does not employ either a deadlock-prevention or a deadlock
avoidance algorithm, then a deadlock situation may arise. In this environment, the
system can provide an algorithm that examines the state of the system to
determine whether a deadlock has occurred and an algorithm to recover from the
deadlock (if a deadlock has indeed occurred).
• In the absence of algorithms to detect and recover from deadlocks, we may arrive
at a situation in which the system is in a deadlocked state yet has no way of
recognizing what has happened. Ignoring the possibility of deadlocks is cheaper
than the other approaches.
Deadlock Prevention
• By ensuring that at least one of these conditions cannot hold, we can prevent the
occurrence of a deadlock.
Mutual Exclusion
• Have enough resources to provide simultaneous execution
• Make all process independent.
Hold & Wait
• whenever a process requests a resource, it does not hold any other resources. One
protocol that we can use requires each process to request and be allocated all its
resources before it begins execution.
• An alternative protocol allows a process to request resources only when it has
none. A process may request some resources and use them. Before it can request
any additional resources, it must release all the resources that it is currently
allocated
No Preemption
• If a process is holding some resources and requests another resource that cannot
be immediately allocated to it ,then all resources the process is currently holding
are preempted.
• Alternatively, if a process requests some resources , check whether they are
available. If they are, allocate them else check whether they are allocated to some
other process that is waiting for additional resources.
If so, we preempt the desired resources from the waiting process and allocate them
to the requesting process. If the resources are neither available nor held by a
waiting process, the requesting process must wait.
Circular Wait
• One way to ensure that this condition never holds is to impose a total ordering of
all resource types and to require that each process requests resources in an
increasing order of enumeration
DeadLock Avoidance
• Banker’s Algorithm used to identify the system is in safe state or not
• A resource allocation algorithm.
Example
Contd.
<p1,p3,p4,p2,p0>
??
• The process P1 requests one additional instance of resource type A and
two instances of resource type C, so Request = (1,0,2)
• Whether OS allocates the resources??
Resource Request Allocation
1.If Request ≤ Need , go to step 2.
Otherwise, raise an error condition, since the process has exceeded its maximum
claim.
2. If Request ≤ Available, go to step 3.
Otherwise, Pi must wait, since the resources are not available.
3. Available = Available–Request ;
Allocation = Allocation + Request ;
Need = Need –Request;
Contd.
• To decide whether this request can be immediately granted, we first check that
Request1 ≤ Available—that is, that (1,0,2) ≤ (3,3,2), which is true. We then
pretend that this request has been fulfilled, and we arrive at the following new
state
Contd.
<p1,p3,p4,p0,p2>
ASSIGNMENT
• A request for (3,3,0) by P4 & a request for (0,2,0) by P0 granted OR not??
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
wait-for graph
• If all resources have only a single instance, then we can define a
deadlockdetection algorithm that uses a variant of the resource-allocation graph,
called a wait-for graph.
• We obtain this graph from the resource-allocation graph by removing the resource
nodes and collapsing the appropriate edges.An edge Pi → Pj exists in a wait-for
graph if and only if the corresponding resourceallocation 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
Contd.
resource-allocation system with multiple
instances
• The wait-for graph scheme is not applicable to a resource-allocation system with
multiple instances of each resource type.
• Banker’s Algorithm
Example
<p0,p2,p3,p1,p4>
Contd.
• process P2 makes one additional request for an instance of type C.
• System is in deadlock state.
DeadLock Detection
• When should we invoke the detection algorithm?
1. How often is a deadlock likely to occur?
2. How many processes will be affected by deadlock when it happens?
Recovery from Deadlock
• When a detection algorithm determines that a deadlock exists, several alternatives
are available. One possibility is to let the system recover from the deadlock
automatically.
• There are two options for breaking a deadlock.
1. One is simply to abort one or more processes to break the circular wait.
2. The other is to preempt some resources from one or more of the deadlocked
processes
Process Termination
• To eliminate deadlocks by aborting a process, we use one of two methods.
1. Abort all deadlocked processes. This method clearly will break the deadlock
cycle, but at great expense. The deadlocked processes may have computed for a
long time, and the results of these partial computations must be discarded and
probably will have to be recomputed later.
2. Abort one process at a time until the deadlock cycle is eliminated. This
method incurs considerable overhead, since after each process is aborted, a
deadlock-detection algorithm must be invoked to determine whether any
processes are still deadlocked
Contd.
• Many factors may affect which process is chosen, including:
1. What the priority of the process is
2. How long the process has computed and how much longer the process will
compute before completing its designated task
3. How many and what types of resources the process has used (for example,
whether the resources are simple to preempt)
4. How many more resources the process needs in order to complete.
5. How many processes will need to be terminated
Resource Preemption
• If preemption is required to deal with deadlocks, then three issues need to be
addressed:
1. Selecting a victim
2. Rollback
3. starvation

More Related Content

Similar to osvzjsjjdndnnssnnsnsndndndnndeadlock.pptx

OS Module-3 (2).pptx
OS Module-3 (2).pptxOS Module-3 (2).pptx
OS Module-3 (2).pptxKokilaK25
 
Deadlock in Distributed Systems
Deadlock in Distributed SystemsDeadlock in Distributed Systems
Deadlock in Distributed SystemsPritom Saha Akash
 
deadlocks.pptx
deadlocks.pptxdeadlocks.pptx
deadlocks.pptxJOHNZHOU52
 
Mch7 deadlock
Mch7 deadlockMch7 deadlock
Mch7 deadlockwahab13
 
Deadlocks prefinal
Deadlocks prefinalDeadlocks prefinal
Deadlocks prefinalmarangburu42
 
Deadlocksprefinal 161014115456
Deadlocksprefinal 161014115456Deadlocksprefinal 161014115456
Deadlocksprefinal 161014115456marangburu42
 
14th November - Deadlock Prevention, Avoidance.ppt
14th November - Deadlock Prevention, Avoidance.ppt14th November - Deadlock Prevention, Avoidance.ppt
14th November - Deadlock Prevention, Avoidance.pptUnknown664473
 
Deadlocks by wani zahoor
Deadlocks by wani zahoorDeadlocks by wani zahoor
Deadlocks by wani zahoorWani Zahoor
 
Deadlock in Operating System
Deadlock in Operating SystemDeadlock in Operating System
Deadlock in Operating SystemAUST
 
Lecture 6- Deadlocks.pptx
Lecture 6- Deadlocks.pptxLecture 6- Deadlocks.pptx
Lecture 6- Deadlocks.pptxAmanuelmergia
 

Similar to osvzjsjjdndnnssnnsnsndndndnndeadlock.pptx (20)

OS Module-3 (2).pptx
OS Module-3 (2).pptxOS Module-3 (2).pptx
OS Module-3 (2).pptx
 
Gp1242 007 oer ppt
Gp1242 007 oer pptGp1242 007 oer ppt
Gp1242 007 oer ppt
 
Chapter 4
Chapter 4Chapter 4
Chapter 4
 
deadlock part5 unit 2.ppt
deadlock part5 unit 2.pptdeadlock part5 unit 2.ppt
deadlock part5 unit 2.ppt
 
Ch07 deadlocks
Ch07 deadlocksCh07 deadlocks
Ch07 deadlocks
 
Deadlock in Distributed Systems
Deadlock in Distributed SystemsDeadlock in Distributed Systems
Deadlock in Distributed Systems
 
Deadlock (1).ppt
Deadlock (1).pptDeadlock (1).ppt
Deadlock (1).ppt
 
Deadlock
DeadlockDeadlock
Deadlock
 
Sucet os module_3_notes
Sucet os module_3_notesSucet os module_3_notes
Sucet os module_3_notes
 
deadlocks.pptx
deadlocks.pptxdeadlocks.pptx
deadlocks.pptx
 
Mch7 deadlock
Mch7 deadlockMch7 deadlock
Mch7 deadlock
 
Deadlocks prefinal
Deadlocks prefinalDeadlocks prefinal
Deadlocks prefinal
 
Deadlocksprefinal 161014115456
Deadlocksprefinal 161014115456Deadlocksprefinal 161014115456
Deadlocksprefinal 161014115456
 
14th November - Deadlock Prevention, Avoidance.ppt
14th November - Deadlock Prevention, Avoidance.ppt14th November - Deadlock Prevention, Avoidance.ppt
14th November - Deadlock Prevention, Avoidance.ppt
 
DeadlockMar21.ppt
DeadlockMar21.pptDeadlockMar21.ppt
DeadlockMar21.ppt
 
Deadlocks Part- II.pdf
Deadlocks Part- II.pdfDeadlocks Part- II.pdf
Deadlocks Part- II.pdf
 
Deadlocks by wani zahoor
Deadlocks by wani zahoorDeadlocks by wani zahoor
Deadlocks by wani zahoor
 
Os5
Os5Os5
Os5
 
Deadlock in Operating System
Deadlock in Operating SystemDeadlock in Operating System
Deadlock in Operating System
 
Lecture 6- Deadlocks.pptx
Lecture 6- Deadlocks.pptxLecture 6- Deadlocks.pptx
Lecture 6- Deadlocks.pptx
 

Recently uploaded

20240419 - Measurecamp Amsterdam - SAM.pdf
20240419 - Measurecamp Amsterdam - SAM.pdf20240419 - Measurecamp Amsterdam - SAM.pdf
20240419 - Measurecamp Amsterdam - SAM.pdfHuman37
 
Industrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdfIndustrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdfLars Albertsson
 
办理(Vancouver毕业证书)加拿大温哥华岛大学毕业证成绩单原版一比一
办理(Vancouver毕业证书)加拿大温哥华岛大学毕业证成绩单原版一比一办理(Vancouver毕业证书)加拿大温哥华岛大学毕业证成绩单原版一比一
办理(Vancouver毕业证书)加拿大温哥华岛大学毕业证成绩单原版一比一F La
 
High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...
High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...
High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...soniya singh
 
Customer Service Analytics - Make Sense of All Your Data.pptx
Customer Service Analytics - Make Sense of All Your Data.pptxCustomer Service Analytics - Make Sense of All Your Data.pptx
Customer Service Analytics - Make Sense of All Your Data.pptxEmmanuel Dauda
 
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM TRACKING WITH GOOGLE ANALYTICS.pptx
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM  TRACKING WITH GOOGLE ANALYTICS.pptxEMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM  TRACKING WITH GOOGLE ANALYTICS.pptx
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM TRACKING WITH GOOGLE ANALYTICS.pptxthyngster
 
04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationships04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationshipsccctableauusergroup
 
RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998YohFuh
 
Predictive Analysis - Using Insight-informed Data to Determine Factors Drivin...
Predictive Analysis - Using Insight-informed Data to Determine Factors Drivin...Predictive Analysis - Using Insight-informed Data to Determine Factors Drivin...
Predictive Analysis - Using Insight-informed Data to Determine Factors Drivin...ThinkInnovation
 
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...dajasot375
 
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 
How we prevented account sharing with MFA
How we prevented account sharing with MFAHow we prevented account sharing with MFA
How we prevented account sharing with MFAAndrei Kaleshka
 
INTERNSHIP ON PURBASHA COMPOSITE TEX LTD
INTERNSHIP ON PURBASHA COMPOSITE TEX LTDINTERNSHIP ON PURBASHA COMPOSITE TEX LTD
INTERNSHIP ON PURBASHA COMPOSITE TEX LTDRafezzaman
 
办理学位证纽约大学毕业证(NYU毕业证书)原版一比一
办理学位证纽约大学毕业证(NYU毕业证书)原版一比一办理学位证纽约大学毕业证(NYU毕业证书)原版一比一
办理学位证纽约大学毕业证(NYU毕业证书)原版一比一fhwihughh
 
Data Science Jobs and Salaries Analysis.pptx
Data Science Jobs and Salaries Analysis.pptxData Science Jobs and Salaries Analysis.pptx
Data Science Jobs and Salaries Analysis.pptxFurkanTasci3
 
RadioAdProWritingCinderellabyButleri.pdf
RadioAdProWritingCinderellabyButleri.pdfRadioAdProWritingCinderellabyButleri.pdf
RadioAdProWritingCinderellabyButleri.pdfgstagge
 
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...Suhani Kapoor
 

Recently uploaded (20)

20240419 - Measurecamp Amsterdam - SAM.pdf
20240419 - Measurecamp Amsterdam - SAM.pdf20240419 - Measurecamp Amsterdam - SAM.pdf
20240419 - Measurecamp Amsterdam - SAM.pdf
 
Industrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdfIndustrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdf
 
Decoding Loan Approval: Predictive Modeling in Action
Decoding Loan Approval: Predictive Modeling in ActionDecoding Loan Approval: Predictive Modeling in Action
Decoding Loan Approval: Predictive Modeling in Action
 
办理(Vancouver毕业证书)加拿大温哥华岛大学毕业证成绩单原版一比一
办理(Vancouver毕业证书)加拿大温哥华岛大学毕业证成绩单原版一比一办理(Vancouver毕业证书)加拿大温哥华岛大学毕业证成绩单原版一比一
办理(Vancouver毕业证书)加拿大温哥华岛大学毕业证成绩单原版一比一
 
High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...
High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...
High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...
 
Customer Service Analytics - Make Sense of All Your Data.pptx
Customer Service Analytics - Make Sense of All Your Data.pptxCustomer Service Analytics - Make Sense of All Your Data.pptx
Customer Service Analytics - Make Sense of All Your Data.pptx
 
Deep Generative Learning for All - The Gen AI Hype (Spring 2024)
Deep Generative Learning for All - The Gen AI Hype (Spring 2024)Deep Generative Learning for All - The Gen AI Hype (Spring 2024)
Deep Generative Learning for All - The Gen AI Hype (Spring 2024)
 
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM TRACKING WITH GOOGLE ANALYTICS.pptx
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM  TRACKING WITH GOOGLE ANALYTICS.pptxEMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM  TRACKING WITH GOOGLE ANALYTICS.pptx
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM TRACKING WITH GOOGLE ANALYTICS.pptx
 
04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationships04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationships
 
RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998
 
Predictive Analysis - Using Insight-informed Data to Determine Factors Drivin...
Predictive Analysis - Using Insight-informed Data to Determine Factors Drivin...Predictive Analysis - Using Insight-informed Data to Determine Factors Drivin...
Predictive Analysis - Using Insight-informed Data to Determine Factors Drivin...
 
E-Commerce Order PredictionShraddha Kamble.pptx
E-Commerce Order PredictionShraddha Kamble.pptxE-Commerce Order PredictionShraddha Kamble.pptx
E-Commerce Order PredictionShraddha Kamble.pptx
 
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...
 
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
 
How we prevented account sharing with MFA
How we prevented account sharing with MFAHow we prevented account sharing with MFA
How we prevented account sharing with MFA
 
INTERNSHIP ON PURBASHA COMPOSITE TEX LTD
INTERNSHIP ON PURBASHA COMPOSITE TEX LTDINTERNSHIP ON PURBASHA COMPOSITE TEX LTD
INTERNSHIP ON PURBASHA COMPOSITE TEX LTD
 
办理学位证纽约大学毕业证(NYU毕业证书)原版一比一
办理学位证纽约大学毕业证(NYU毕业证书)原版一比一办理学位证纽约大学毕业证(NYU毕业证书)原版一比一
办理学位证纽约大学毕业证(NYU毕业证书)原版一比一
 
Data Science Jobs and Salaries Analysis.pptx
Data Science Jobs and Salaries Analysis.pptxData Science Jobs and Salaries Analysis.pptx
Data Science Jobs and Salaries Analysis.pptx
 
RadioAdProWritingCinderellabyButleri.pdf
RadioAdProWritingCinderellabyButleri.pdfRadioAdProWritingCinderellabyButleri.pdf
RadioAdProWritingCinderellabyButleri.pdf
 
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
 

osvzjsjjdndnnssnnsnsndndndnndeadlock.pptx

  • 2. What?? • Two or more processes are waiting for an event which is never going to occur. • A process requests resources; if the resources are not available at that time, the process enters a waiting state. Sometimes, a waiting process is never again able to change state, because the resources it has requested are held by other waiting processes. This situation is called a deadlock.
  • 3. System Model • A process may utilize a resource in only the following sequence: 1. Request: The process requests the resource. If the request cannot be granted immediately (for example, if the resource is being used by another process), then the requesting process must wait until it can acquire the resource. 2. Use: The process can operate on the resource (for example, if the resource is a printer, the process can print on the printer). 3. Release: The process releases the resource.
  • 4. Why?? • Due to four conditions that hold simultaneously in a system. 1. Mutual exclusion. 2. Hold and wait 3. No pre-emption 4. Circular wait
  • 5. Resource-Allocation Graph • Deadlocks can be described more precisely in terms of a directed graph called a system resource-allocation graph. • This graph consists of a set of vertices V and a set of edges E. a) The set of vertices V is partitioned into two different types of nodes: P = {P1, P2, ..., Pn}, the set consisting of all the active processes in the system, and R = {R1, R2, ..., Rm}, the set consisting of all resource types in the system.
  • 6. Contd. b) A directed edge from process Pi to resource type Rj is denoted by Pi → Rj ; it signifies that process Pi has requested an instance of resource type Rj and is currently waiting for that resource. A directed edge from resource type Rj to process Pi is denoted by Rj → Pi ; it signifies that an instance of resource type Rj has been allocated to process Pi . A directed edge Pi → Rj is called a request edge; a directed edge Rj → Pi is called an assignment edge.
  • 7. Contd. • Pictorially, we represent each process Pi as a circle and each resource type Rj as a rectangle. Since resource type Rj may have more than one instance, we represent each such instance as a dot within the rectangle. • If the graph contains no cycles, then no process in the system is deadlocked. If the graph does contain a cycle, then a deadlock may exist.
  • 8. Example The sets P, R, and E: P = {P1, P2, P3} R = {R1, R2, R3, R4} E = {P1 → R1, P2 → R3, R1 → P2, R2 → P2, R2 → P1, R3 → P3} Resource instances: • One instance of resource type R1 • Two instances of resource type R2 • One instance of resource type R3 • Three instances of resource type R4 Process states: • Process P1 is holding an instance of resource type R2 and is waiting for an instance of resource type R1. • Process P2 is holding an instance of R1 and an instance of R2 and is waiting for an instance of R3. • Process P3 is holding an instance of R3.
  • 9. Contd. • If the cycle involves only a set of resource types, each of which has only a single instance, then a deadlock has occurred. Each process involved in the cycle is deadlocked. In this case, a cycle in the graph is both a necessary and a sufficient condition for the existence of deadlock. • If each resource type has several instances, then a cycle does not necessarily imply that a deadlock has occurred. In this case, a cycle in the graph is a necessary but not a sufficient condition for the existence of deadlock.
  • 10. Contd. Resource-allocation graph with a cycle but no deadlock. Resource-allocation graph with a deadlock.
  • 11. Contd. • if a resource-allocation graph does not have a cycle, then the system is not in a deadlocked state. If there is a cycle, then the system may or may not be in a deadlocked state.
  • 12. How?? • Can deal with the deadlock problem in one of three ways: 1. We can use a protocol to prevent or avoid deadlocks, ensuring that the system will never enter a deadlocked state. 2. We can allow the system to enter a deadlocked state, detect it, and recover. 3. We can ignore the problem altogether and pretend that deadlocks never occur in the system.
  • 13. Contd. • Deadlock prevention provides a set of methods to ensure that at least one of the necessary conditions cannot hold. These methods prevent deadlocks by constraining how requests for resources can be made. • Deadlock avoidance requires that the operating system be given additional information in advance concerning which resources a process will request and use during its lifetime. With this additional knowledge, the operating system can decide for each request whether or not the process should wait.
  • 14. Contd. • If a system does not employ either a deadlock-prevention or a deadlock avoidance algorithm, then a deadlock situation may arise. In this environment, the system can provide an algorithm that examines the state of the system to determine whether a deadlock has occurred and an algorithm to recover from the deadlock (if a deadlock has indeed occurred). • In the absence of algorithms to detect and recover from deadlocks, we may arrive at a situation in which the system is in a deadlocked state yet has no way of recognizing what has happened. Ignoring the possibility of deadlocks is cheaper than the other approaches.
  • 15. Deadlock Prevention • By ensuring that at least one of these conditions cannot hold, we can prevent the occurrence of a deadlock.
  • 16. Mutual Exclusion • Have enough resources to provide simultaneous execution • Make all process independent.
  • 17. Hold & Wait • whenever a process requests a resource, it does not hold any other resources. One protocol that we can use requires each process to request and be allocated all its resources before it begins execution. • An alternative protocol allows a process to request resources only when it has none. A process may request some resources and use them. Before it can request any additional resources, it must release all the resources that it is currently allocated
  • 18. No Preemption • If a process is holding some resources and requests another resource that cannot be immediately allocated to it ,then all resources the process is currently holding are preempted. • Alternatively, if a process requests some resources , check whether they are available. If they are, allocate them else check whether they are allocated to some other process that is waiting for additional resources. If so, we preempt the desired resources from the waiting process and allocate them to the requesting process. If the resources are neither available nor held by a waiting process, the requesting process must wait.
  • 19. Circular Wait • One way to ensure that this condition never holds is to impose a total ordering of all resource types and to require that each process requests resources in an increasing order of enumeration
  • 20. DeadLock Avoidance • Banker’s Algorithm used to identify the system is in safe state or not • A resource allocation algorithm.
  • 23. ?? • The process P1 requests one additional instance of resource type A and two instances of resource type C, so Request = (1,0,2) • Whether OS allocates the resources??
  • 24. Resource Request Allocation 1.If Request ≤ Need , go to step 2. Otherwise, raise an error condition, since the process has exceeded its maximum claim. 2. If Request ≤ Available, go to step 3. Otherwise, Pi must wait, since the resources are not available. 3. Available = Available–Request ; Allocation = Allocation + Request ; Need = Need –Request;
  • 25. Contd. • To decide whether this request can be immediately granted, we first check that Request1 ≤ Available—that is, that (1,0,2) ≤ (3,3,2), which is true. We then pretend that this request has been fulfilled, and we arrive at the following new state
  • 27. ASSIGNMENT • A request for (3,3,0) by P4 & a request for (0,2,0) by P0 granted OR not??
  • 28. 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
  • 29. wait-for graph • If all resources have only a single instance, then we can define a deadlockdetection algorithm that uses a variant of the resource-allocation graph, called a wait-for graph. • We obtain this graph from the resource-allocation graph by removing the resource nodes and collapsing the appropriate edges.An edge Pi → Pj exists in a wait-for graph if and only if the corresponding resourceallocation 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
  • 31. resource-allocation system with multiple instances • The wait-for graph scheme is not applicable to a resource-allocation system with multiple instances of each resource type. • Banker’s Algorithm
  • 33. Contd. • process P2 makes one additional request for an instance of type C. • System is in deadlock state.
  • 34. DeadLock Detection • When should we invoke the detection algorithm? 1. How often is a deadlock likely to occur? 2. How many processes will be affected by deadlock when it happens?
  • 35. Recovery from Deadlock • When a detection algorithm determines that a deadlock exists, several alternatives are available. One possibility is to let the system recover from the deadlock automatically. • There are two options for breaking a deadlock. 1. One is simply to abort one or more processes to break the circular wait. 2. The other is to preempt some resources from one or more of the deadlocked processes
  • 36. Process Termination • To eliminate deadlocks by aborting a process, we use one of two methods. 1. Abort all deadlocked processes. This method clearly will break the deadlock cycle, but at great expense. The deadlocked processes may have computed for a long time, and the results of these partial computations must be discarded and probably will have to be recomputed later. 2. Abort one process at a time until the deadlock cycle is eliminated. This method incurs considerable overhead, since after each process is aborted, a deadlock-detection algorithm must be invoked to determine whether any processes are still deadlocked
  • 37. Contd. • Many factors may affect which process is chosen, including: 1. What the priority of the process is 2. How long the process has computed and how much longer the process will compute before completing its designated task 3. How many and what types of resources the process has used (for example, whether the resources are simple to preempt) 4. How many more resources the process needs in order to complete. 5. How many processes will need to be terminated
  • 38. Resource Preemption • If preemption is required to deal with deadlocks, then three issues need to be addressed: 1. Selecting a victim 2. Rollback 3. starvation