EEE 435 Principles of Operating Systems - PowerPoint PPT Presentation

1 / 20
About This Presentation
Title:

EEE 435 Principles of Operating Systems

Description:

For this solution to our deadlock problem, we accept that ... Doomsday. Device. Allocated to process 2. Fall 2003. Capt MWP LeSauvage. Deadlock Detection ... – PowerPoint PPT presentation

Number of Views:66
Avg rating:3.0/5.0
Slides: 21
Provided by: mikeles
Category:

less

Transcript and Presenter's Notes

Title: EEE 435 Principles of Operating Systems


1
EEE 435Principles of Operating Systems
  • Deadlock Detection and Recovery
  • (Modern Operating Systems 3.4)

2
Quick Review
  • What are our four conditions for deadlock?
  • How are we going to try and solve it? (four
    ways)

3
Outline
  • Deadlock Detection
  • One resource of each type
  • Multiple resources of each type
  • Recovery from a detected deadlock

4
Deadlocks
  • For this solution to our deadlock problem, we
    accept that deadlocks will happen but we build a
    system for detection of deadlocks and the means
    to recover from them
  • Is this practical in the real world?

5
Deadlock Detection
  • Consider systems with only single instances of
    each resource type
  • For example, one printer, one scanner, one
    magnetic storage
  • Multiple instances of each type will be
    considered later in this class
  • We have used directed graphs to easily see where
    a deadlock loop exists, can we implement an
    algorithm to do the same?

6
Deadlock Detection
  • Draw this on your next slide
  • Process A holds R and wants S
  • Process B holds nothing but wants T
  • Process C holds nothing but wants S
  • Process D holds U and wants S and T
  • Process E holds T and wants V
  • Process F holds W and wants S
  • Process G holds V and wants U

7
Deadlock Detection
8
Deadlock Detection
  • How can we implement an algorithm that detects a
    deadlock the same way our eyes do?
  • Create a list of nodes (called L) and follow out
    all connections from each node, adding nodes to
    the list when they are followed
  • If a node appears in the list twice, we know we
    have followed a loop!
  • Specific details, next slide, stay tuned!

9
Deadlock Detection
  • 1) For each node, N, in the graph, perform the
    following steps with N as the starting node
  • 2) Initialize L as an empty list and all arcs as
    unmarked
  • 3) Add the current node to the end of L and check
    to see if it appears in L twice. If it does, the
    graph contains a cycle and the algorithm
    terminates
  • 4) From the given node, see if there are any
    unmarked outgoing arcs. If so, go to step 5 if
    not, go to step 6
  • 5) Pick an unmarked outgoing arc at random and
    mark it. Then follow it to the new current node
    and go to step 3
  • 6) The algorithm is at a dead end. Remove the
    current node, go back to the node from which we
    came, and go to step 3. If this node is the
    initial node then the graph contains no cycles

10
Deadlock Detection
  • (empty for drawing demonstration of algorithm)

11
Deadlock Detection
  • The solution for deadlock detection works for
    single instances of resources, but what about
    when we have multiple disks/printers/etc?
  • One solution is matrix-based and uses four data
    structures to identify deadlock conditions
  • m resource classes (ie m2, printer, scanner)
  • Ei instances of each resource class (1?i ? m)
  • E is the existing resource vector
  • A is the available resource vector
  • Two matrices current allocation (C) and
    request(R)

12
Deadlock Detection
Resources in Existence (E1, E2, E3, ..., Em)
Resources Available (A1, A2, A3, ..., Am)
Doomsday Device
Scanner
Modem
Printer
Current Allocation Matrix
Request Matrix
Needed by process 1
Allocated to process 2
13
Deadlock Detection
  • How do we use these four data structures to
    detect a deadlock?
  • Vector comparison. Define A?B to mean that each
    element of A is less than or equal to the
    corresponding element of B
  • Mathematically, A?B is true iff Ai?Bi for 1?i?m
  • Start by designating each process unmarked
  • Once a process is marked it indicates that it
    is able to complete and is therefore not
    deadlocked (that process in particular)

14
Deadlock Detection
  • How do we use these four data structures to
    detect a deadlock?
  • Now apply the following algorithm
  • 1) Look for an unmarked process, Pi, for which
    the i-th row of R is less than or equal to A
  • 2) If such a process is found, add the i-th row
    of C to A, mark the process, and go to step 1
  • 3) If no such process exists, the algorithm
    terminates
  • If there are any unmarked processes at the
    termination of the algorithm, they are deadlocked

15
Deadlock Detection
  • Example Is there a deadlock here?

16
Deadlock Recovery
  • Now that we can detect deadlock, how can we
    recover from it?
  • There are no good choices, just the lesser evil
    from a number of candidates
  • Recovery through preemption
  • Recovery through rollback
  • Recovery through killing processes

17
Deadlock Recovery
  • Recovery through preemption
  • It may be possible to take a resource away from a
    process and give it to another
  • This may require manual intervention (ie go to
    the printer and remove the sheets printed so far
    so as not to group them with the output from the
    other process)
  • This method is highly dependent on the nature of
    the resource frequently difficult or impossible
    (writing to a database but only half done...can
    you really interrupt this?)

18
Deadlock Recovery
  • Recovery through rollback
  • Processes are checkpointed periodically.
    Everything required to restart them in exactly
    the state they are in is written to file
    (including which resources are assigned to which
    resources)
  • If a deadlock occurs, a previous state can be
    restored and certain processes delayed so that
    the resources are not requested and deadlock does
    not occur
  • Disadvantage time and resources taken to save
    the state

19
Deadlock Recovery
  • Recovery through killing processes
  • Crude, effective, but potentially damaging
  • Best to kill a process in the cycle if it wont
    disrupt all other processes in the cycle.
    Alternatively, another victim holding a required
    resource (that he is using but never plans on
    giving back so he is not technically part of the
    cycle) can be killed
  • Best choice a process that can be rerun from the
    start with no ill effects
  • Worst choice processes that modify static
    resources such as databases

20
Quiz Time!
  • Questions?
Write a Comment
User Comments (0)
About PowerShow.com