SlideShare a Scribd company logo
2
Most read
3
Most read
Methods for Handling Deadlocks
Generally speaking, we can deal with the deadlock problem in one of three ways:
 We can use a protocol to prevent or avoid deadlocks, ensuring that the system will never
enter a deadlocked state.
 We can allow the system to enter a deadlocked state, detect it, and recover.
 We can ignore the problem altogether and pretend that deadlocks never occur in the system.
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. To decide whether the current request can be satisfied or must be delayed, the system
must consider the resources currently available, the resources currently allocated to each process,
and the future requests and releases of each process.
Deadlock Prevention
We elaborate on this approach by examining each of the four necessary conditions separately
Mutual Exclusion The mutual exclusion condition must hold. That is, at least one resource must
be nonsharable. Sharable resources, in contrast, do not require mutually exclusive access and thus
cannot be involved in a deadlock.
Hold and Wait To ensure that the hold-and-wait condition never occurs in the system, we must
guarantee that, whenever a process requests a resource, it does not hold any other resources.
No Preemption The third necessary condition for deadlocks is that there be no preemption of
resources that have already been allocated. To ensure that this condition does not hold, we can use
the following protocol. If a process is holding some resources and requests another resource that
cannot be immediately allocated to it (that is, the process must wait), then all resources the process
is currently holding are preempted. In otherwords, these resources are implicitly released. The
preempted resources are added to the list of resources for which the process is waiting.
Circular wait To avoid circular wait, resources may be ordered and we can ensure that each
process can request resources only in an increasing order of these numbers.
Deadlock Avoidance
Safe State
A state is safe if the system can allocate resources to each process (up to its maximum) in some
order and still avoid a deadlock. More formally, a system is in a safe state only if there exists a
safe sequence. A sequence of processes <P1, P2, ..., Pn> is a safe sequence for the current
allocation state if, for each Pi , the resource requests that Pi can still make can be satisfied by the
currently available resources plus the resources held by all Pj, with j < i. In this situation, if the
resources that Pi needs are not immediately available, then Pi can wait until all Pj have finished.
When they have finished, Pi can obtain all of its needed resources, complete its designated task,
return its allocated resources, and terminate. When Pi terminates, Pi+1 can obtain its needed
resources, and so on. If no such sequence exists, then the system state is said to be unsafe. A safe
state is not a deadlocked state. Conversely, a deadlocked state is an unsafe state. Not all unsafe
states are deadlocks, however (Figure 7.6). An unsafe state may lead to a deadlock.
Resource-Allocation-Graph Algorithm
In addition to the request and assignment edges already described, we introduce a new type of
edge, called a claim edge. A claim edge Pi → Rj indicates that process Pi may request resource
Rj at some time in the future. This edge resembles a request edge in direction but is represented in
the graph by a dashed line. When process Pi requests resource Rj , the claim edge Pi → Rj is
converted to a request edge. Similarly, when a resource Rj is released by Pi , the assignment edge
Rj → Pi is reconverted to a claim edge Pi → Rj .
Now suppose that process Pi requests resource Rj. The request can be granted only if converting
the request edge Pi → Rj to an assignment edge Rj → Pi does not result in the formation of a cycle
in the resource-allocation graph. If no cycle exists, then the allocation of the resource will leave
the system in a safe state. If a cycle is found, then the allocation will put the system in an unsafe
state.
To illustrate this algorithm, we consider the resource-allocation graph of Figure 7.7. Suppose that
P2 requests R2. Although R2 is currently free, we cannot allocate it to P2, since this action will
create a cycle in the graph (Figure 7.8). A cycle, as mentioned, indicates that the system is in an
unsafe state. If P1 requests R2, and P2 requests R1, then a deadlock will occur.

More Related Content

PPTX
System calls
PPT
Chapter 7 - Deadlocks
PPT
deadlock avoidance
PPT
Deadlock
PPTX
Deadlock Avoidance in Operating System
PPTX
Bankers algorithm
PPTX
Deadlocks in operating system
PDF
Deadlock Avoidance - OS
System calls
Chapter 7 - Deadlocks
deadlock avoidance
Deadlock
Deadlock Avoidance in Operating System
Bankers algorithm
Deadlocks in operating system
Deadlock Avoidance - OS

What's hot (20)

PPTX
Message passing in Distributed Computing Systems
PPTX
deadlock handling
PPT
Clock synchronization in distributed system
PPTX
CPU Scheduling in OS Presentation
PPT
Paging.ppt
PPTX
Distributed shred memory architecture
PPTX
Distributed Transactions(flat and nested) and Atomic Commit Protocols
PPTX
Deadlock ppt
PPT
Process management in os
PPTX
Deadlock Prevention
DOC
Naming in Distributed System
PDF
Deadlock
PPTX
serializability in dbms
PPTX
Concurrency control
PPTX
Inter Process Communication
PPTX
Cpu scheduling in operating System.
PPT
Thrashing allocation frames.43
PPT
15. Transactions in DBMS
PPT
Deadlock detection and recovery by saad symbian
PDF
Message passing in Distributed Computing Systems
deadlock handling
Clock synchronization in distributed system
CPU Scheduling in OS Presentation
Paging.ppt
Distributed shred memory architecture
Distributed Transactions(flat and nested) and Atomic Commit Protocols
Deadlock ppt
Process management in os
Deadlock Prevention
Naming in Distributed System
Deadlock
serializability in dbms
Concurrency control
Inter Process Communication
Cpu scheduling in operating System.
Thrashing allocation frames.43
15. Transactions in DBMS
Deadlock detection and recovery by saad symbian
Ad

Similar to Methods for handling deadlocks (20)

PPTX
6. Deadlock_1640227623705.pptx
PPT
FP 202 Chapter 2 - Part 3
PDF
Os unit 4
PDF
Deadlock in Distributed Systems
PPT
Deadlock
PPT
Ch07 deadlocks
PDF
deadlock.pdfdkfglknalkdnglqgjlejgooooo;o
PDF
deadlocks for Engenerring for he purpose
PPTX
osvzjsjjdndnnssnnsnsndndndnndeadlock.pptx
PPT
Mch7 deadlock
PDF
Deadlocks
PPTX
Module 3 Deadlocks.pptx
PPTX
Algorithm 4Chapter Four- Deadlock (5).pptx
PPTX
Gp1242 007 oer ppt
PPT
Deadlock.ppt
PPTX
OS Module-3 (2).pptx
PDF
Deadlocks
PPT
6. Deadlock_1640227623705.pptx
FP 202 Chapter 2 - Part 3
Os unit 4
Deadlock in Distributed Systems
Deadlock
Ch07 deadlocks
deadlock.pdfdkfglknalkdnglqgjlejgooooo;o
deadlocks for Engenerring for he purpose
osvzjsjjdndnnssnnsnsndndndnndeadlock.pptx
Mch7 deadlock
Deadlocks
Module 3 Deadlocks.pptx
Algorithm 4Chapter Four- Deadlock (5).pptx
Gp1242 007 oer ppt
Deadlock.ppt
OS Module-3 (2).pptx
Deadlocks
Ad

More from A. S. M. Shafi (20)

DOCX
Data Warehouse Schema (Star, Snowflake).docx
PDF
Correlation Analysis in Machine Learning.pdf
PDF
Naive Bayes and Decision Tree Algorithm.pdf
PDF
Frequent Pattern Growth Mining Algorithm.pdf
PDF
Direct Hashing and Pruning Algorithm in Data MIning.pdf
PDF
Association Rule Mining with Apriori Algorithm.pdf
PDF
HITS Algorithm in Data and Web MIning.pdf
PDF
Page Rank Algorithm in Data Mining and Web Application.pdf
PDF
K Nearest Neighbor Classifier in Machine Learning.pdf
PDF
K Means Clustering Algorithm in Machine Learning.pdf
PDF
2D Transformation in Computer Graphics
PDF
3D Transformation in Computer Graphics
PDF
Projection
PDF
2D Transformation
PDF
Line drawing algorithm
PDF
Fragmentation
PDF
File organization
PDF
Bankers algorithm
PDF
RR and priority scheduling
PDF
Fcfs and sjf
Data Warehouse Schema (Star, Snowflake).docx
Correlation Analysis in Machine Learning.pdf
Naive Bayes and Decision Tree Algorithm.pdf
Frequent Pattern Growth Mining Algorithm.pdf
Direct Hashing and Pruning Algorithm in Data MIning.pdf
Association Rule Mining with Apriori Algorithm.pdf
HITS Algorithm in Data and Web MIning.pdf
Page Rank Algorithm in Data Mining and Web Application.pdf
K Nearest Neighbor Classifier in Machine Learning.pdf
K Means Clustering Algorithm in Machine Learning.pdf
2D Transformation in Computer Graphics
3D Transformation in Computer Graphics
Projection
2D Transformation
Line drawing algorithm
Fragmentation
File organization
Bankers algorithm
RR and priority scheduling
Fcfs and sjf

Recently uploaded (20)

PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
RMMM.pdf make it easy to upload and study
PPTX
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PPTX
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
Classroom Observation Tools for Teachers
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
01-Introduction-to-Information-Management.pdf
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
Insiders guide to clinical Medicine.pdf
PPTX
master seminar digital applications in india
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PPTX
Pharma ospi slides which help in ospi learning
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
RMMM.pdf make it easy to upload and study
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
102 student loan defaulters named and shamed – Is someone you know on the list?
Renaissance Architecture: A Journey from Faith to Humanism
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
Microbial disease of the cardiovascular and lymphatic systems
Classroom Observation Tools for Teachers
human mycosis Human fungal infections are called human mycosis..pptx
01-Introduction-to-Information-Management.pdf
2.FourierTransform-ShortQuestionswithAnswers.pdf
Insiders guide to clinical Medicine.pdf
master seminar digital applications in india
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
STATICS OF THE RIGID BODIES Hibbelers.pdf
PPH.pptx obstetrics and gynecology in nursing
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Pharma ospi slides which help in ospi learning

Methods for handling deadlocks

  • 1. Methods for Handling Deadlocks Generally speaking, we can deal with the deadlock problem in one of three ways:  We can use a protocol to prevent or avoid deadlocks, ensuring that the system will never enter a deadlocked state.  We can allow the system to enter a deadlocked state, detect it, and recover.  We can ignore the problem altogether and pretend that deadlocks never occur in the system. 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. To decide whether the current request can be satisfied or must be delayed, the system must consider the resources currently available, the resources currently allocated to each process, and the future requests and releases of each process. Deadlock Prevention We elaborate on this approach by examining each of the four necessary conditions separately Mutual Exclusion The mutual exclusion condition must hold. That is, at least one resource must be nonsharable. Sharable resources, in contrast, do not require mutually exclusive access and thus cannot be involved in a deadlock. Hold and Wait To ensure that the hold-and-wait condition never occurs in the system, we must guarantee that, whenever a process requests a resource, it does not hold any other resources. No Preemption The third necessary condition for deadlocks is that there be no preemption of resources that have already been allocated. To ensure that this condition does not hold, we can use the following protocol. If a process is holding some resources and requests another resource that cannot be immediately allocated to it (that is, the process must wait), then all resources the process is currently holding are preempted. In otherwords, these resources are implicitly released. The preempted resources are added to the list of resources for which the process is waiting. Circular wait To avoid circular wait, resources may be ordered and we can ensure that each process can request resources only in an increasing order of these numbers. Deadlock Avoidance Safe State A state is safe if the system can allocate resources to each process (up to its maximum) in some order and still avoid a deadlock. More formally, a system is in a safe state only if there exists a safe sequence. A sequence of processes <P1, P2, ..., Pn> is a safe sequence for the current allocation state if, for each Pi , the resource requests that Pi can still make can be satisfied by the currently available resources plus the resources held by all Pj, with j < i. In this situation, if the
  • 2. resources that Pi needs are not immediately available, then Pi can wait until all Pj have finished. When they have finished, Pi can obtain all of its needed resources, complete its designated task, return its allocated resources, and terminate. When Pi terminates, Pi+1 can obtain its needed resources, and so on. If no such sequence exists, then the system state is said to be unsafe. A safe state is not a deadlocked state. Conversely, a deadlocked state is an unsafe state. Not all unsafe states are deadlocks, however (Figure 7.6). An unsafe state may lead to a deadlock. Resource-Allocation-Graph Algorithm In addition to the request and assignment edges already described, we introduce a new type of edge, called a claim edge. A claim edge Pi → Rj indicates that process Pi may request resource Rj at some time in the future. This edge resembles a request edge in direction but is represented in the graph by a dashed line. When process Pi requests resource Rj , the claim edge Pi → Rj is converted to a request edge. Similarly, when a resource Rj is released by Pi , the assignment edge Rj → Pi is reconverted to a claim edge Pi → Rj . Now suppose that process Pi requests resource Rj. The request can be granted only if converting the request edge Pi → Rj to an assignment edge Rj → Pi does not result in the formation of a cycle in the resource-allocation graph. If no cycle exists, then the allocation of the resource will leave the system in a safe state. If a cycle is found, then the allocation will put the system in an unsafe state.
  • 3. To illustrate this algorithm, we consider the resource-allocation graph of Figure 7.7. Suppose that P2 requests R2. Although R2 is currently free, we cannot allocate it to P2, since this action will create a cycle in the graph (Figure 7.8). A cycle, as mentioned, indicates that the system is in an unsafe state. If P1 requests R2, and P2 requests R1, then a deadlock will occur.