SlideShare una empresa de Scribd logo
1 de 15
 By the end of this class, student will be able to:
1) Explain how to handle deadlock
   The cause of deadlocks:
-   Each process needing what another process has.
-   This results from sharing resources such as memory,
    devices, links.

   Under normal operation, a resource allocations proceed
    like this::
    1. Request a resource (suspend until available if
        necessary )
    2. Use the resource.
    3. Release the resource.
•Traffic only in one direction.
•Each section of a bridge can be viewed as a resource.
•If a deadlock occurs, it can be resolved if one car backs up
(preempt resources and rollback).
•Several cars may have to be backed up if a deadlock occurs.
•Starvation is possible
NECESSARY CONDITIONS
ALL of these four must happen simultaneously for a deadlock to
occur:
 1) Mutual exclusion
 One or more than one resource must be held by a process in a non-
 sharable (exclusive) mode.

 2) Hold and Wait
 A process holds a resource while waiting for another resource.

 3) No Preemption
 There is only voluntary release of a resource - nobody else can make a
 process give up a resource.

 4) Circular Wait
 Process A waits for Process B waits for Process C .... waits for Process A.
A visual ( mathematical ) way to determine if a deadlock has, or may occur.
 
    G = ( V, E )            The graph contains nodes and edges.
     
    V              Nodes consist of processes = { P1, P2, P3, ...} and resource
      types
          { R1, R2, ...}
     
    E              Edges are ( Pi, Rj ) or ( Ri, Pj )
 
An arrow from the process to resource indicates the process is requesting
the resource. An arrow from resource to process shows an instance of the
resource has been allocated to the process.
 
Process is a circle, resource type is square; dots represent number of instances
of resource in type. Request points to square, assignment comes from dot.


                     Pi                    Pi                Pi
                                                   Rj                Rj
If   the graph contains no cycles, then no process is deadlocked.
   If there is a cycle, then:
      a) If resource types have multiple instances, then deadlock MAY
         exist.
      b) If each resource type has 1 instance, then deadlock has occurred.
                                                              R3 Assigned to P3


    Resource allocation graph


                                                             P2 Requests P3
Resource allocation graph
                             Resource allocation graph
    with a deadlock.
                            with a cycle but no deadlock.
There are three methods:
 
Ignore Deadlocks:                    Most Operating systems do this!!

Ensure deadlock never occurs using either
 
      Prevention Prevent any one of the 4 conditions from happening.
     
      Avoidance Allow all deadlock conditions, but calculate cycles about to
                  happen and stop dangerous operations..
 
 
Allow deadlock to happen. This requires using both:
 
      Detection Know a deadlock has occurred.
     
      Recovery Regain the resources.
Do not allow one of the four conditions to occur.

1) Mutual exclusion:
    a) Automatically holds for printers and other non-sharables.
    b) Shared entities (read only files) don't need mutual exclusion (and aren’t
       susceptible to deadlock.)
    c)   Prevention not possible, since some devices are intrinsically non-
       sharable.

2) Hold and wait:
    a) Collect all resources before execution.
    b) A particular resource can only be requested when no others are being
       held. A sequence of resources is always collected beginning with the
       same one.
    c) Utilization is low, starvation possible.
Deadlock Prevention
3) No preemption:
 
    a) Release any resource already being held if the process can't get an
       additional resource.
    b) Allow preemption - if a needed resource is held by another process,
       which is also waiting on some resource, steal it. Otherwise wait.
 
4) Circular wait:
 
    a) Number resources and only request in ascending order.
    b) EACH of these prevention techniques may cause a decrease in
       utilization and/or resources. For this reason, prevention isn't
       necessarily the best technique.
    c) Prevention is generally the easiest to implement.
If we have prior knowledge of how resources will be requested, it's possible to
determine if we are entering an "unsafe" state.
 
Possible states are:
 
      Deadlock         No forward progress can be made.
       
      Unsafe state A state that may allow deadlock.
       
      Safe state       A state is safe if a sequence of processes exist such that there
                       are enough resources for the first to finish, and as each
                       finishes and releases its resources there are enough for the
                       next to finish.
 
The rule is simple: If a request allocation would cause an unsafe state, do not honor
that request.
 
NOTE: All deadlocks are unsafe, but all unsafes are NOT deadlocks.

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

Dead lock
Dead lockDead lock
Dead lock
 
Dead Lock In Operating Systems
Dead Lock In Operating SystemsDead Lock In Operating Systems
Dead Lock In Operating Systems
 
Deadlock
DeadlockDeadlock
Deadlock
 
Deadlocks by wani zahoor
Deadlocks by wani zahoorDeadlocks by wani zahoor
Deadlocks by wani zahoor
 
Deadlocks in operating system
Deadlocks in operating systemDeadlocks in operating system
Deadlocks in operating system
 
OS - Deadlock
OS - DeadlockOS - Deadlock
OS - Deadlock
 
Deadlock- Operating System
Deadlock- Operating SystemDeadlock- Operating System
Deadlock- Operating System
 
Deadlocks
DeadlocksDeadlocks
Deadlocks
 
Chapter 4
Chapter 4Chapter 4
Chapter 4
 
Deadlock
DeadlockDeadlock
Deadlock
 
Deadlock Presentation
Deadlock PresentationDeadlock Presentation
Deadlock Presentation
 
Lect05
Lect05Lect05
Lect05
 
Deadlocks in operating system
Deadlocks in operating systemDeadlocks in operating system
Deadlocks in operating system
 
Deadlocks
Deadlocks Deadlocks
Deadlocks
 
Chapter 7 - Deadlocks
Chapter 7 - DeadlocksChapter 7 - Deadlocks
Chapter 7 - Deadlocks
 
deadlock detection using Goldman's algorithm by ANIKET CHOUDHURY
deadlock detection using Goldman's algorithm by ANIKET CHOUDHURYdeadlock detection using Goldman's algorithm by ANIKET CHOUDHURY
deadlock detection using Goldman's algorithm by ANIKET CHOUDHURY
 
7 Deadlocks
7 Deadlocks7 Deadlocks
7 Deadlocks
 
Deadlock
DeadlockDeadlock
Deadlock
 
Gp1242 007 oer ppt
Gp1242 007 oer pptGp1242 007 oer ppt
Gp1242 007 oer ppt
 
Methods for handling deadlocks
Methods for handling deadlocksMethods for handling deadlocks
Methods for handling deadlocks
 

Destacado (7)

Web Project Proposal
Web Project ProposalWeb Project Proposal
Web Project Proposal
 
Operating system Dead lock
Operating system Dead lockOperating system Dead lock
Operating system Dead lock
 
Greedy Algorithms with examples' b-18298
Greedy Algorithms with examples'  b-18298Greedy Algorithms with examples'  b-18298
Greedy Algorithms with examples' b-18298
 
Deadlock
DeadlockDeadlock
Deadlock
 
Knapsack Problem
Knapsack ProblemKnapsack Problem
Knapsack Problem
 
Final project proposal
Final project proposalFinal project proposal
Final project proposal
 
Sample Website Proposal Presentation
Sample Website Proposal PresentationSample Website Proposal Presentation
Sample Website Proposal Presentation
 

Similar a FP 202 Chapter 2 - Part 3

Chapter 03
Chapter 03Chapter 03
Chapter 03
Google
 
osvzjsjjdndnnssnnsnsndndndnndeadlock.pptx
osvzjsjjdndnnssnnsnsndndndnndeadlock.pptxosvzjsjjdndnnssnnsnsndndndnndeadlock.pptx
osvzjsjjdndnnssnnsnsndndndnndeadlock.pptx
Bhaskar271887
 
Mch7 deadlock
Mch7 deadlockMch7 deadlock
Mch7 deadlock
wahab13
 

Similar a FP 202 Chapter 2 - Part 3 (20)

Section07-Deadlocks (1).ppt
Section07-Deadlocks (1).pptSection07-Deadlocks (1).ppt
Section07-Deadlocks (1).ppt
 
Section07-Deadlocks_operating_system.ppt
Section07-Deadlocks_operating_system.pptSection07-Deadlocks_operating_system.ppt
Section07-Deadlocks_operating_system.ppt
 
Ch 4 deadlock
Ch 4 deadlockCh 4 deadlock
Ch 4 deadlock
 
Section07-Deadlocks.pdf
Section07-Deadlocks.pdfSection07-Deadlocks.pdf
Section07-Deadlocks.pdf
 
Chapter 03
Chapter 03Chapter 03
Chapter 03
 
Deadlock
DeadlockDeadlock
Deadlock
 
Deadlock in Distributed Systems
Deadlock in Distributed SystemsDeadlock in Distributed Systems
Deadlock in Distributed Systems
 
Deadlock Detection Algorithm
Deadlock Detection AlgorithmDeadlock Detection Algorithm
Deadlock Detection Algorithm
 
Os module 2 d
Os module 2 dOs module 2 d
Os module 2 d
 
ikh311-05
ikh311-05ikh311-05
ikh311-05
 
osvzjsjjdndnnssnnsnsndndndnndeadlock.pptx
osvzjsjjdndnnssnnsnsndndndnndeadlock.pptxosvzjsjjdndnnssnnsnsndndndnndeadlock.pptx
osvzjsjjdndnnssnnsnsndndndnndeadlock.pptx
 
Deadlock and memory management -- Operating System
Deadlock and memory management -- Operating SystemDeadlock and memory management -- Operating System
Deadlock and memory management -- Operating System
 
Deadlocks prefinal
Deadlocks prefinalDeadlocks prefinal
Deadlocks prefinal
 
Deadlocksprefinal 161014115456
Deadlocksprefinal 161014115456Deadlocksprefinal 161014115456
Deadlocksprefinal 161014115456
 
OS-Part-06.pdf
OS-Part-06.pdfOS-Part-06.pdf
OS-Part-06.pdf
 
Mch7 deadlock
Mch7 deadlockMch7 deadlock
Mch7 deadlock
 
Deadlocks
DeadlocksDeadlocks
Deadlocks
 
Deadlocks final
Deadlocks finalDeadlocks final
Deadlocks final
 
Deadlock
DeadlockDeadlock
Deadlock
 
Deadlock detection & prevention
Deadlock detection & preventionDeadlock detection & prevention
Deadlock detection & prevention
 

Más de rohassanie

Course outline FP202 - Dis 2012
Course outline FP202 - Dis 2012Course outline FP202 - Dis 2012
Course outline FP202 - Dis 2012
rohassanie
 
FP 201 - Unit 6
FP 201 - Unit 6FP 201 - Unit 6
FP 201 - Unit 6
rohassanie
 
FP 201 - Unit4 Part 2
FP 201 - Unit4 Part 2FP 201 - Unit4 Part 2
FP 201 - Unit4 Part 2
rohassanie
 
FP 201 - Unit 3 Part 2
FP 201 - Unit 3 Part 2FP 201 - Unit 3 Part 2
FP 201 - Unit 3 Part 2
rohassanie
 
FP 202 - Chapter 5
FP 202 - Chapter 5FP 202 - Chapter 5
FP 202 - Chapter 5
rohassanie
 
Chapter 3 part 2
Chapter 3 part 2Chapter 3 part 2
Chapter 3 part 2
rohassanie
 
Chapter 3 part 1
Chapter 3 part 1Chapter 3 part 1
Chapter 3 part 1
rohassanie
 
FP 201 Unit 2 - Part 3
FP 201 Unit 2 - Part 3FP 201 Unit 2 - Part 3
FP 201 Unit 2 - Part 3
rohassanie
 
FP 201 Unit 2 - Part 2
FP 201 Unit 2 - Part 2FP 201 Unit 2 - Part 2
FP 201 Unit 2 - Part 2
rohassanie
 
Chapter 2 (Part 2)
Chapter 2 (Part 2) Chapter 2 (Part 2)
Chapter 2 (Part 2)
rohassanie
 
Labsheet 7 FP 201
Labsheet 7 FP 201Labsheet 7 FP 201
Labsheet 7 FP 201
rohassanie
 
Labsheet 6 - FP 201
Labsheet 6 - FP 201Labsheet 6 - FP 201
Labsheet 6 - FP 201
rohassanie
 
Jadual Waktu Sesi JUN 2012
Jadual Waktu Sesi JUN 2012Jadual Waktu Sesi JUN 2012
Jadual Waktu Sesi JUN 2012
rohassanie
 
Chapter 2 part 1
Chapter 2 part 1Chapter 2 part 1
Chapter 2 part 1
rohassanie
 
FP 201 Unit 3
FP 201 Unit 3 FP 201 Unit 3
FP 201 Unit 3
rohassanie
 

Más de rohassanie (20)

Course outline FP202 - Dis 2012
Course outline FP202 - Dis 2012Course outline FP202 - Dis 2012
Course outline FP202 - Dis 2012
 
FP 201 - Unit 6
FP 201 - Unit 6FP 201 - Unit 6
FP 201 - Unit 6
 
Fp201 unit5 1
Fp201 unit5 1Fp201 unit5 1
Fp201 unit5 1
 
FP 201 - Unit4 Part 2
FP 201 - Unit4 Part 2FP 201 - Unit4 Part 2
FP 201 - Unit4 Part 2
 
Fp201 unit4
Fp201 unit4Fp201 unit4
Fp201 unit4
 
FP 201 - Unit 3 Part 2
FP 201 - Unit 3 Part 2FP 201 - Unit 3 Part 2
FP 201 - Unit 3 Part 2
 
FP 202 - Chapter 5
FP 202 - Chapter 5FP 202 - Chapter 5
FP 202 - Chapter 5
 
Chapter 3 part 2
Chapter 3 part 2Chapter 3 part 2
Chapter 3 part 2
 
Chapter 3 part 1
Chapter 3 part 1Chapter 3 part 1
Chapter 3 part 1
 
FP 201 Unit 2 - Part 3
FP 201 Unit 2 - Part 3FP 201 Unit 2 - Part 3
FP 201 Unit 2 - Part 3
 
FP 201 Unit 2 - Part 2
FP 201 Unit 2 - Part 2FP 201 Unit 2 - Part 2
FP 201 Unit 2 - Part 2
 
Lab ex 1
Lab ex 1Lab ex 1
Lab ex 1
 
Chapter 2 (Part 2)
Chapter 2 (Part 2) Chapter 2 (Part 2)
Chapter 2 (Part 2)
 
Labsheet 7 FP 201
Labsheet 7 FP 201Labsheet 7 FP 201
Labsheet 7 FP 201
 
Labsheet 6 - FP 201
Labsheet 6 - FP 201Labsheet 6 - FP 201
Labsheet 6 - FP 201
 
Jadual Waktu Sesi JUN 2012
Jadual Waktu Sesi JUN 2012Jadual Waktu Sesi JUN 2012
Jadual Waktu Sesi JUN 2012
 
Labsheet 5
Labsheet 5Labsheet 5
Labsheet 5
 
Labsheet 4
Labsheet 4Labsheet 4
Labsheet 4
 
Chapter 2 part 1
Chapter 2 part 1Chapter 2 part 1
Chapter 2 part 1
 
FP 201 Unit 3
FP 201 Unit 3 FP 201 Unit 3
FP 201 Unit 3
 

FP 202 Chapter 2 - Part 3

  • 1.
  • 2.  By the end of this class, student will be able to: 1) Explain how to handle deadlock
  • 3. The cause of deadlocks: - Each process needing what another process has. - This results from sharing resources such as memory, devices, links.  Under normal operation, a resource allocations proceed like this:: 1. Request a resource (suspend until available if necessary ) 2. Use the resource. 3. Release the resource.
  • 4. •Traffic only in one direction. •Each section of a bridge can be viewed as a resource. •If a deadlock occurs, it can be resolved if one car backs up (preempt resources and rollback). •Several cars may have to be backed up if a deadlock occurs. •Starvation is possible
  • 5. NECESSARY CONDITIONS ALL of these four must happen simultaneously for a deadlock to occur: 1) Mutual exclusion One or more than one resource must be held by a process in a non- sharable (exclusive) mode. 2) Hold and Wait A process holds a resource while waiting for another resource. 3) No Preemption There is only voluntary release of a resource - nobody else can make a process give up a resource. 4) Circular Wait Process A waits for Process B waits for Process C .... waits for Process A.
  • 6. A visual ( mathematical ) way to determine if a deadlock has, or may occur.   G = ( V, E ) The graph contains nodes and edges.   V Nodes consist of processes = { P1, P2, P3, ...} and resource types { R1, R2, ...}   E Edges are ( Pi, Rj ) or ( Ri, Pj )   An arrow from the process to resource indicates the process is requesting the resource. An arrow from resource to process shows an instance of the resource has been allocated to the process.   Process is a circle, resource type is square; dots represent number of instances of resource in type. Request points to square, assignment comes from dot. Pi Pi Pi Rj Rj
  • 7.
  • 8.
  • 9.
  • 10. If the graph contains no cycles, then no process is deadlocked.  If there is a cycle, then: a) If resource types have multiple instances, then deadlock MAY exist. b) If each resource type has 1 instance, then deadlock has occurred. R3 Assigned to P3 Resource allocation graph P2 Requests P3
  • 11. Resource allocation graph Resource allocation graph with a deadlock. with a cycle but no deadlock.
  • 12. There are three methods:   Ignore Deadlocks: Most Operating systems do this!! Ensure deadlock never occurs using either   Prevention Prevent any one of the 4 conditions from happening.   Avoidance Allow all deadlock conditions, but calculate cycles about to happen and stop dangerous operations..     Allow deadlock to happen. This requires using both:   Detection Know a deadlock has occurred.   Recovery Regain the resources.
  • 13. Do not allow one of the four conditions to occur. 1) Mutual exclusion: a) Automatically holds for printers and other non-sharables. b) Shared entities (read only files) don't need mutual exclusion (and aren’t susceptible to deadlock.) c) Prevention not possible, since some devices are intrinsically non- sharable. 2) Hold and wait: a) Collect all resources before execution. b) A particular resource can only be requested when no others are being held. A sequence of resources is always collected beginning with the same one. c) Utilization is low, starvation possible.
  • 14. Deadlock Prevention 3) No preemption:   a) Release any resource already being held if the process can't get an additional resource. b) Allow preemption - if a needed resource is held by another process, which is also waiting on some resource, steal it. Otherwise wait.   4) Circular wait:   a) Number resources and only request in ascending order. b) EACH of these prevention techniques may cause a decrease in utilization and/or resources. For this reason, prevention isn't necessarily the best technique. c) Prevention is generally the easiest to implement.
  • 15. If we have prior knowledge of how resources will be requested, it's possible to determine if we are entering an "unsafe" state.   Possible states are:   Deadlock No forward progress can be made.   Unsafe state A state that may allow deadlock.   Safe state A state is safe if a sequence of processes exist such that there are enough resources for the first to finish, and as each finishes and releases its resources there are enough for the next to finish.   The rule is simple: If a request allocation would cause an unsafe state, do not honor that request.   NOTE: All deadlocks are unsafe, but all unsafes are NOT deadlocks.