Presentation is loading. Please wait.

Presentation is loading. Please wait.

Process Management Deadlocks.

Similar presentations


Presentation on theme: "Process Management Deadlocks."— Presentation transcript:

1 Process Management Deadlocks

2 system model A system contains a finite number of resources
examples of resources: CPU, memory, files, I/O devices resources must be distributed to processes resource utilization by processes Request receive resource if available or wait for it to become available O/S uses a table to keep track of resources & puts processes in a waiting queue for access Use resource Release resource for other processes to use Usually an O/S system call handles requests and releases, but… some resource allocation uses a software mutex lock or semaphores

3 déjà vu – review (mutual exclusion) (can be used with request and release of resources)

4 déjà vu – review (mutual exclusion) (can be used with request and release of resources)

5 But, they seemed like a good idea at the time…
Mutual Exclusion… But, they seemed like a good idea at the time…

6 What is a deadlock? a specific condition when two processes are each waiting for each other to release a resource, or more than two processes are waiting for resources in a circular chain Usually caused by specific type of mutually exclusive resource known as a software lock.

7 Necessary for a deadlock:
4 conditions occurring simultaneously Mutual Exclusion (a resource being held without sharing) Hold & Wait ( a process holding 1+ resources & waiting on acquire additional resources that are currently being used by other processes) causing.. 4. Circular Wait (a set of waiting processes holding resources in a circular chain) No Preemption (resources can only be released voluntarily by holding process)

8 system resource allocation directed graph (digraph)
P = process R= resource E= edge request (PR) assignment (RP) . = instance of a resource 1 . 3 . 1 2 3 5 . 2 . 4 . If a cycle exists, there may be a deadlock.

9 cycle with NO deadlock P = process R= resource E= edge
request (P->R) assignment (R->P) . = instance of a resource 2 1 . 1 3 2 . 4

10 methods for handling the problem of deadlocks
use a protocol to prevent/avoid deadlocks prevention: set of methods so that at least one of the necessary conditions cannot hold avoidance: O/S gets advance list of resources a process will use in its lifetime - used to decide whether a process should wait for resource allow a deadlock, but detect it, & recover ignore it - like it doesn’t exist used by most O/S, including UNIX & Windows responsibility passes to application program developers

11 deadlock prevention = restraining requests
Mutual exclusion undeniable for nonsharable resources Hold & Wait request & allocate all resources before execution resources allocated only when none are held ( must release all currently held resources) lowers the ability to use resources efficiently possible starvation situation Circular Wait requests resources (which are in a hierarchy) in order only (programmers must respect ordering when coding ) release resources of a lower order, before receiving resources of a higher order No Preemption works only if resource can be preempted and easily restored i.e. CPU registers and memory not for mutex locks and semaphores if a process must wait for a resource, all currently held resources must be released while waiting check if all required resources are available before starting process Deadlock can still occur

12 deadlock avoidance 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… try to make only those transitions that will take you from one safe state to another avoid transitions to unsafe state (a state that is not deadlocked, and is not safe)

13 deadlock avoidance - utilizing Resource Allocation Graph Algorithm
P = process R= resource E= edge request (P->R) assignment (R->P) . = single instance of a resource (no more!) NEW! ---> claim edge 1 . 1 2 Stop! unsafe state Go! still safe 2 .

14 deadlock avoidance - Banker’s Algorithm
Declare all needed resources if state is still stable - run process if not - wait until another process releases its resources, then run Data structures needed: available – array of system resources & # of each type max – 2D array of processes and their maximum resource requirements allocation – 2D array of processes and their current resource allocation need – 2 D array of processes ( need = max – allocation) 2 Algorithms needed: Safety Resource Request

15 deadlock avoidance - Banker’s Algorithm
Data structures needed: available – array of system resources & # of each type max – 2D array of processes and their maximum resource requirements allocation – 2D array of processes and their current resource allocation need – 2 D array of processes ( need = max – allocation) Safety Algorithm: work[] = available[] (work is temporary storage) & initialize all finish[ i (#of processes) ] = false Scan all processes for work needed to be completed finish[i]==false && need of process i <= work (for each resource) if incomplete process with allocatable resources is found: work = work + allocation (no problem – remove process from list) finish[i]=true If finish[i] == true for all processes, then system is in a safe state

16 deadlock avoidance - Banker’s Algorithm
Data structures needed: available – array of system resources & # of each type max – 2D array of processes and their maximum resource requirements allocation – 2D array of processes and their current resource allocation need – 2 D array of processes ( need = max – allocation) Resource Request Algorithm: if request of process i > need of process i ERROR! request greater than initial requirements else if request of process i > available WAIT! (resources are not available) simulate a temporary allocation of resources if still in safe state: proceed with allocation else: wait!

17 Deadlock Detection Requirements:
algorithm that examines the state of the system to determine if a deadlock has occurred algorithm to recover from the deadlock

18 Deadlock Detection Instances of resource types
multiple instances: run Banker’s safety algorithm assume process is not deadlocked if resources can be allocated (may be deadlocked upon later inspection) if finish[i]==false, then process P[i] is deadlocked single instance: use “wait-for” graph system maintains a “wait-for” graph periodically search graph for a cycle deadlock exists if the “wait-for” graph contains a cycle

19 Resource Allocation Graph Vs. Wait-For Graph

20 Deadlock Detection - Usage
Factors for usage: deadlock occurrence # of affected processes Cases: extreme: each time a resource is requested points to process causing deadlock & affected cycle processes more practical: defined intervals (e.g. once per hour) CPU utilization drop (e.g. <40%) both do not point to “culprit” or affected processes as more than 1 cycle may exist

21 recovery from deadlock
manually ( inform operator) automatically (system fix) abort processes abort all deadlocked processes abort 1 process at a time until deadlock condition is removed choosing a victim: What is the process’s priority? How long has it been computing? How close is it to finishing its task? How many, and what type of resources has it used? How many resources will it need to finish? How many child processes will also need to be terminated? Is the process interactive or batch?

22 recovery from deadlock
automatically (system fix) preempt resources from deadlocked processes select a victim (focus on resource allocation) rollback process to safe state extreme overhead – keeping track of safe state on all processes total rollback – abort process & restart it protect against starvation – bounded preemption

23 Bottom line… it is easier to pretend it never happened.

24 Let’s review… See Study Guide (7.1 – 7.8)

25 Storage Management - File System Interface
The end of Chapter 7! Have a nice evening! Go Home… & READ CHAPTER 11 Storage Management - File System Interface


Download ppt "Process Management Deadlocks."

Similar presentations


Ads by Google