SlideShare una empresa de Scribd logo
1 de 24
Descargar para leer sin conexión
DEADLOCK
A process request the resources,
the resources are not available at
that time, so the process enter
into the waiting state. The
requesting resources are held by
another waiting process, both are
in waiting state, this situation is
CONDITIONS
  FOR
DEADLOCK
A Deadlocked system must satisfied the
following 4 conditions. These are :

1. MUTUAL EXCLUSION

2. HOLD AND WAIT

3. NO PREEMPTION

4. CIRCULAR WAIT
Deadlock

Aviodence
Avoid actions that may lead to a deadlock.
Think of it as a state machine moving from 1
state to another as each instruction is
executed.
We can avoid the situattion of deadlocked
by:
    1.Safe State
    2.Banker‟s Algorithm
    3.Resource Allocation Graph
Safe State
Safe state is one where :
                           It is not a deadlocked
state There is some sequence by which all
requests can be satisfied.
To avoid deadlocks, we try to make only those
transitions that will take you from one safe
state to another. We avoid transitions to
unsafe state (a state that is not deadlocked,
and is not safe)
Unsafe
 Deadlock



             Safe


Safe unsafe and deadlock state spaces
Banker's Algorithm
When a request is made, check to see if after
the request is satisfied, there is a (atleast one!)
sequence of moves that can satisfy all the
requests ie. the new state is safe. If so,
satisfy the request, else make the request
wait.
Resource Allocation Graph
If we have a resource allocation
system with only one inatance of each
process, a varient of the resource
allocation graph can be used for
deadlock avoidence.
R2
     R1

                                      P3
P1                  P2


     R3                      R4

          Resource Allocation Graph
DEADLOCK

PREVENTIONS
Difference from avoidance is that here, the
system itself is build in such a way that
there are no deadlocks.
Make sure atleast one of the 4 deadlock
conditions is never satisfied.
This may however be even more conservative
than deadlock avoidance strategy.
MUTUAL EXCLUSION:
                                      We can deny this condition
                                        by simple protocol i.e.,
                                     “convert the all non-sharable
                                         resources to sharable
                                              resources”.
                                                                       HOLD AND WAIT : We
                                                                       can deny this condition with
CIRCULAR WAIT : We ensure                                              following two protocols :
   that circular wait must not
  happened if we apply a simple                                         “A process request the
 solution, i.e., numbering all the                                       resources only when the
 resources types and each process                                        process has none”.
request resources in an increasing
      order of enumeration                                             • “Each process to request and
                                                                          be allocated all its resources
                                                                          before it begins execution”.

                                     NO PREEMPTION :To ensure
                                       that this condition does not
                                        hold, we use the following
                                        protocol : we preempt the
                                        desired resources from the
                                      waiting process and allocate
                                     them to the requesting process.
Deadlock

Detection
Detection mechanism of deadlocks for single instance
of resource type is different. We can detect the dead
locks using wait for graph for single instance resource
type and detect using detection algorithm for multiple
instances of resource type.
1.SINGLE INSTANCE OF RESOURCE TYPE :
 Single instance of resource type means, the system
 consisting of only one resource for one type. We can
 detect this type of deadlocks with the help of wait
 for graph.
P1        R1      P2        P2     R2       P3



                               P2                       P3
      P1



           P2     R3      P1        P3     R4      P2

                            Wait for graph

       A system is in deadlock state , if and only if the wait for graph
contains cycles. So we can detect the deadlocks with cycles. In the
figure there is 2 cycles one is P1 to P2 to P1, second one P2 to P3 to P2
so the system consisting of deadlocks.
2. SEVERAL INSTANCE OF
   RESOURCE TYPE
The wait for graph is not applicable to several
instance of resource type. So we need another
method for this type, that is “deadlock detection
algorithm”. This algorithm looks like „Banker‟s
algorithm” and it employees several data
structures that are similar to those used in the
Banker‟s algorithm.
Deadlock

recovery
Once deadlock has been detected, some strategy

is needed for recovery. The various approaches

of recovering from deadlock are:

                  PROCESS TERMINATION

               RESOURCE PREEMPTION
PROCESS TERMINATION
  “Process termination” it is one method to recover
   from deadlock. We uses 2 methods for process
   termination, these are:
a) ABORT ALL DEADLOCKED PROCESS : It
   means release all the processes in the deadlocked
   state, and start the allocation from the starting
   point. It is a great expensive method.
b) ABORT ONE BY ONE PROCESS UNTIL THE
   DEADLOCK CYCLE IS ELIMINATED : In this
   method first abort the one of the processes in
   the deadlocked state, and allocated the
   resources to some other process in the deadlock
RESOURCE PREEMPTION
To eliminate deadlocks using resource preemption,
   preempt some resources
from processes and give these resources to other
processes until the deadlock cycle is broken.
There are 3 methods to eliminate the deadlocks using
resource preemption.These are :
a) SELECTING A VICTIM : Select a victim resource
   from the deadlock state, and preempt that one.
b) ROLLBACK : If a resource from a process is
   preempted, what should be done with that process.
   The process must be roll backed to some safe state
   and restart it from that state.
c) STARVATION : It must be guaranteed that
Deadlock Detection and Recovery Methods

Más contenido relacionado

La actualidad más candente

Deadlock Avoidance - OS
Deadlock Avoidance - OSDeadlock Avoidance - OS
Deadlock Avoidance - OSMsAnita2
 
Process in operating system
Process in operating systemProcess in operating system
Process in operating systemChetan Mahawar
 
Dead Lock in operating system
Dead Lock in operating systemDead Lock in operating system
Dead Lock in operating systemAli Haider
 
Threads (operating System)
Threads (operating System)Threads (operating System)
Threads (operating System)Prakhar Maurya
 
Memory Management in OS
Memory Management in OSMemory Management in OS
Memory Management in OSvampugani
 
Cpu scheduling in operating System.
Cpu scheduling in operating System.Cpu scheduling in operating System.
Cpu scheduling in operating System.Ravi Kumar Patel
 
Inter Process Communication Presentation[1]
Inter Process Communication Presentation[1]Inter Process Communication Presentation[1]
Inter Process Communication Presentation[1]Ravindra Raju Kolahalam
 
Data Structure and Algorithms.pptx
Data Structure and Algorithms.pptxData Structure and Algorithms.pptx
Data Structure and Algorithms.pptxSyed Zaid Irshad
 
Page replacement algorithms
Page replacement algorithmsPage replacement algorithms
Page replacement algorithmsPiyush Rochwani
 
Distributed DBMS - Unit 8 - Distributed Transaction Management & Concurrency ...
Distributed DBMS - Unit 8 - Distributed Transaction Management & Concurrency ...Distributed DBMS - Unit 8 - Distributed Transaction Management & Concurrency ...
Distributed DBMS - Unit 8 - Distributed Transaction Management & Concurrency ...Gyanmanjari Institute Of Technology
 

La actualidad más candente (20)

CPU Scheduling Algorithms
CPU Scheduling AlgorithmsCPU Scheduling Algorithms
CPU Scheduling Algorithms
 
Operating System: Deadlock
Operating System: DeadlockOperating System: Deadlock
Operating System: Deadlock
 
Semaphore
SemaphoreSemaphore
Semaphore
 
Deadlock Avoidance in Operating System
Deadlock Avoidance in Operating SystemDeadlock Avoidance in Operating System
Deadlock Avoidance in Operating System
 
Deadlock Prevention
Deadlock PreventionDeadlock Prevention
Deadlock Prevention
 
Memory management
Memory managementMemory management
Memory management
 
Deadlock Avoidance - OS
Deadlock Avoidance - OSDeadlock Avoidance - OS
Deadlock Avoidance - OS
 
Process in operating system
Process in operating systemProcess in operating system
Process in operating system
 
Deadlock
DeadlockDeadlock
Deadlock
 
Dead Lock in operating system
Dead Lock in operating systemDead Lock in operating system
Dead Lock in operating system
 
Threads (operating System)
Threads (operating System)Threads (operating System)
Threads (operating System)
 
Memory Management in OS
Memory Management in OSMemory Management in OS
Memory Management in OS
 
Process state in OS
Process state in OSProcess state in OS
Process state in OS
 
Cpu scheduling in operating System.
Cpu scheduling in operating System.Cpu scheduling in operating System.
Cpu scheduling in operating System.
 
Inter Process Communication Presentation[1]
Inter Process Communication Presentation[1]Inter Process Communication Presentation[1]
Inter Process Communication Presentation[1]
 
Distributed DBMS - Unit 6 - Query Processing
Distributed DBMS - Unit 6 - Query ProcessingDistributed DBMS - Unit 6 - Query Processing
Distributed DBMS - Unit 6 - Query Processing
 
Acid properties
Acid propertiesAcid properties
Acid properties
 
Data Structure and Algorithms.pptx
Data Structure and Algorithms.pptxData Structure and Algorithms.pptx
Data Structure and Algorithms.pptx
 
Page replacement algorithms
Page replacement algorithmsPage replacement algorithms
Page replacement algorithms
 
Distributed DBMS - Unit 8 - Distributed Transaction Management & Concurrency ...
Distributed DBMS - Unit 8 - Distributed Transaction Management & Concurrency ...Distributed DBMS - Unit 8 - Distributed Transaction Management & Concurrency ...
Distributed DBMS - Unit 8 - Distributed Transaction Management & Concurrency ...
 

Destacado

Deadlocks in operating system
Deadlocks in operating systemDeadlocks in operating system
Deadlocks in operating systemMidhun Sankar
 
Intro to Deadlocks
Intro to DeadlocksIntro to Deadlocks
Intro to Deadlockslionpeal
 
Operating System Deadlock Galvin
Operating System  Deadlock GalvinOperating System  Deadlock Galvin
Operating System Deadlock GalvinSonali Chauhan
 
Direct memory access
Direct memory accessDirect memory access
Direct memory accessshubham kuwar
 
Virtual memory
Virtual memoryVirtual memory
Virtual memoryAnuj Modi
 
Data integrity
Data integrityData integrity
Data integrityKiran Kota
 
Direct Memory Access(DMA)
Direct Memory Access(DMA)Direct Memory Access(DMA)
Direct Memory Access(DMA)Page Maker
 

Destacado (13)

Chapter 7 - Deadlocks
Chapter 7 - DeadlocksChapter 7 - Deadlocks
Chapter 7 - Deadlocks
 
Deadlocks in operating system
Deadlocks in operating systemDeadlocks in operating system
Deadlocks in operating system
 
Intro to Deadlocks
Intro to DeadlocksIntro to Deadlocks
Intro to Deadlocks
 
Operating System Deadlock Galvin
Operating System  Deadlock GalvinOperating System  Deadlock Galvin
Operating System Deadlock Galvin
 
Semaphores
SemaphoresSemaphores
Semaphores
 
Direct memory access
Direct memory accessDirect memory access
Direct memory access
 
Virtual memory
Virtual memoryVirtual memory
Virtual memory
 
Deadlock
DeadlockDeadlock
Deadlock
 
Data integrity
Data integrityData integrity
Data integrity
 
Data integrity
Data integrityData integrity
Data integrity
 
OS - Deadlock
OS - DeadlockOS - Deadlock
OS - Deadlock
 
Direct Memory Access(DMA)
Direct Memory Access(DMA)Direct Memory Access(DMA)
Direct Memory Access(DMA)
 
Pert cpm
Pert cpmPert cpm
Pert cpm
 

Similar a Deadlock Detection and Recovery Methods

Similar a Deadlock Detection and Recovery Methods (20)

osvishal-160830131208 (1).pdf
osvishal-160830131208 (1).pdfosvishal-160830131208 (1).pdf
osvishal-160830131208 (1).pdf
 
Deadlock
DeadlockDeadlock
Deadlock
 
Deadlock
DeadlockDeadlock
Deadlock
 
Deadlocks by wani zahoor
Deadlocks by wani zahoorDeadlocks by wani zahoor
Deadlocks by wani zahoor
 
Unit 3 part 2(DEADLOCK)
Unit 3 part 2(DEADLOCK)Unit 3 part 2(DEADLOCK)
Unit 3 part 2(DEADLOCK)
 
Deadlock
DeadlockDeadlock
Deadlock
 
Deadlocks
DeadlocksDeadlocks
Deadlocks
 
Rdbms
RdbmsRdbms
Rdbms
 
Deadlock Slides
Deadlock SlidesDeadlock Slides
Deadlock Slides
 
Deadlock in operating systems
Deadlock in operating systemsDeadlock in operating systems
Deadlock in operating systems
 
osvzjsjjdndnnssnnsnsndndndnndeadlock.pptx
osvzjsjjdndnnssnnsnsndndndnndeadlock.pptxosvzjsjjdndnnssnnsnsndndndnndeadlock.pptx
osvzjsjjdndnnssnnsnsndndndnndeadlock.pptx
 
Deadlocks prefinal
Deadlocks prefinalDeadlocks prefinal
Deadlocks prefinal
 
Deadlocksprefinal 161014115456
Deadlocksprefinal 161014115456Deadlocksprefinal 161014115456
Deadlocksprefinal 161014115456
 
Understanding deadlocks in operating system
Understanding deadlocks in operating systemUnderstanding deadlocks in operating system
Understanding deadlocks in operating system
 
Deadlock detection & prevention
Deadlock detection & preventionDeadlock detection & prevention
Deadlock detection & prevention
 
Deadlocks final
Deadlocks finalDeadlocks final
Deadlocks final
 
Ch 4 deadlock
Ch 4 deadlockCh 4 deadlock
Ch 4 deadlock
 
Deadlock in Distributed Systems
Deadlock in Distributed SystemsDeadlock in Distributed Systems
Deadlock in Distributed Systems
 
Unit iv: Deadlocks
Unit iv: DeadlocksUnit iv: Deadlocks
Unit iv: Deadlocks
 
OS Presentation 1 (1).pptx
OS Presentation 1 (1).pptxOS Presentation 1 (1).pptx
OS Presentation 1 (1).pptx
 

Deadlock Detection and Recovery Methods

  • 1.
  • 2. DEADLOCK A process request the resources, the resources are not available at that time, so the process enter into the waiting state. The requesting resources are held by another waiting process, both are in waiting state, this situation is
  • 3.
  • 5. A Deadlocked system must satisfied the following 4 conditions. These are : 1. MUTUAL EXCLUSION 2. HOLD AND WAIT 3. NO PREEMPTION 4. CIRCULAR WAIT
  • 7. Avoid actions that may lead to a deadlock. Think of it as a state machine moving from 1 state to another as each instruction is executed. We can avoid the situattion of deadlocked by: 1.Safe State 2.Banker‟s Algorithm 3.Resource Allocation Graph
  • 8. Safe State Safe state is one where : It is not a deadlocked state There is some sequence by which all requests can be satisfied. To avoid deadlocks, we try to make only those transitions that will take you from one safe state to another. We avoid transitions to unsafe state (a state that is not deadlocked, and is not safe)
  • 9. Unsafe Deadlock Safe Safe unsafe and deadlock state spaces
  • 10. Banker's Algorithm When a request is made, check to see if after the request is satisfied, there is a (atleast one!) sequence of moves that can satisfy all the requests ie. the new state is safe. If so, satisfy the request, else make the request wait.
  • 11. Resource Allocation Graph If we have a resource allocation system with only one inatance of each process, a varient of the resource allocation graph can be used for deadlock avoidence.
  • 12. R2 R1 P3 P1 P2 R3 R4 Resource Allocation Graph
  • 14. Difference from avoidance is that here, the system itself is build in such a way that there are no deadlocks. Make sure atleast one of the 4 deadlock conditions is never satisfied. This may however be even more conservative than deadlock avoidance strategy.
  • 15. MUTUAL EXCLUSION: We can deny this condition by simple protocol i.e., “convert the all non-sharable resources to sharable resources”. HOLD AND WAIT : We can deny this condition with CIRCULAR WAIT : We ensure following two protocols : that circular wait must not happened if we apply a simple “A process request the solution, i.e., numbering all the resources only when the resources types and each process process has none”. request resources in an increasing order of enumeration • “Each process to request and be allocated all its resources before it begins execution”. NO PREEMPTION :To ensure that this condition does not hold, we use the following protocol : we preempt the desired resources from the waiting process and allocate them to the requesting process.
  • 17. Detection mechanism of deadlocks for single instance of resource type is different. We can detect the dead locks using wait for graph for single instance resource type and detect using detection algorithm for multiple instances of resource type. 1.SINGLE INSTANCE OF RESOURCE TYPE : Single instance of resource type means, the system consisting of only one resource for one type. We can detect this type of deadlocks with the help of wait for graph.
  • 18. P1 R1 P2 P2 R2 P3 P2 P3 P1 P2 R3 P1 P3 R4 P2 Wait for graph A system is in deadlock state , if and only if the wait for graph contains cycles. So we can detect the deadlocks with cycles. In the figure there is 2 cycles one is P1 to P2 to P1, second one P2 to P3 to P2 so the system consisting of deadlocks.
  • 19. 2. SEVERAL INSTANCE OF RESOURCE TYPE The wait for graph is not applicable to several instance of resource type. So we need another method for this type, that is “deadlock detection algorithm”. This algorithm looks like „Banker‟s algorithm” and it employees several data structures that are similar to those used in the Banker‟s algorithm.
  • 21. Once deadlock has been detected, some strategy is needed for recovery. The various approaches of recovering from deadlock are:  PROCESS TERMINATION RESOURCE PREEMPTION
  • 22. PROCESS TERMINATION “Process termination” it is one method to recover from deadlock. We uses 2 methods for process termination, these are: a) ABORT ALL DEADLOCKED PROCESS : It means release all the processes in the deadlocked state, and start the allocation from the starting point. It is a great expensive method. b) ABORT ONE BY ONE PROCESS UNTIL THE DEADLOCK CYCLE IS ELIMINATED : In this method first abort the one of the processes in the deadlocked state, and allocated the resources to some other process in the deadlock
  • 23. RESOURCE PREEMPTION To eliminate deadlocks using resource preemption, preempt some resources from processes and give these resources to other processes until the deadlock cycle is broken. There are 3 methods to eliminate the deadlocks using resource preemption.These are : a) SELECTING A VICTIM : Select a victim resource from the deadlock state, and preempt that one. b) ROLLBACK : If a resource from a process is preempted, what should be done with that process. The process must be roll backed to some safe state and restart it from that state. c) STARVATION : It must be guaranteed that