Process Management Deadlocks.

Slides:



Advertisements
Similar presentations
Chapter 7: Deadlocks.
Advertisements

Chapter 7: Deadlocks.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 7: Deadlocks.
7.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Chapter 7: Deadlocks.
Deadlocks CS 3100 Deadlocks1. The Deadlock Problem A set of blocked processes each holding a resource and waiting to acquire a resource held by another.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 8: Deadlocks System Model Deadlock Characterization Methods for Handling Deadlocks.
1 Wednesday, June 28, 2006 Command, n.: Statement presented by a human and accepted by a computer in such a manner as to make the human feel that he is.
Chapter 7: Deadlocks. 7.2 Chapter Objectives To develop a description of deadlocks, which prevent sets of concurrent processes from completing their tasks.
1 Chapter 7: Deadlock. 2 The Deadlock Problem System Model Deadlock Characterization Methods for Handling Deadlocks Deadlock Prevention Deadlock Avoidance.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts - 7 th Edition, Feb 14, 2005 Chapter 7: Deadlocks The Deadlock.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 7: Deadlocks.
Silberschatz, Galvin and Gagne  Operating System Concepts Deadlock and Starvation Deadlock – two or more processes are waiting indefinitely for.
Deadlocks Gordon College Stephen Brinton. Deadlock Overview The Deadlock Problem System Model Deadlock Characterization Methods for Handling Deadlocks.
1 School of Computing Science Simon Fraser University CMPT 300: Operating Systems I Ch 7: Deadlock Dr. Mohamed Hefeeda.
What we will cover…  The Deadlock Problem  System Model  Deadlock Characterization  Methods for Handling Deadlocks  Deadlock Prevention  Deadlock.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts - 7 th Edition, Feb 14, 2005 Objectives Understand the Deadlock.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Deadlocks.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 8: Deadlocks System Model Deadlock Characterization Methods for Handling Deadlocks.
System Model Deadlock Characterization Methods for Handling Deadlocks Deadlock Prevention, Avoidance, and Detection Recovering from Deadlock Combined Approach.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 7: Deadlocks.
Chapter 7 Deadlocks. 7.2 Modified By Dr. Khaled Wassif Operating System Concepts – 7 th Edition Silberschatz, Galvin and Gagne ©2005 Chapter 7: Deadlocks.
Cosc 4740 Chapter 6, Part 4 Deadlocks. The Deadlock Problem A set of blocked processes each holding a resource and waiting to acquire a resource held.
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-6 Deadlocks Department of Computer Science and Software Engineering.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 AE4B33OSS Chapter 7: Deadlocks The Deadlock Problem System Model Deadlock Characterization.
CHAPTER 8: DEADLOCKS System Model Deadlock Characterization
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 7: Deadlocks.
 The Deadlock Problem  System Model  Deadlock Characterization  Methods for Handling Deadlocks  Deadlock Prevention  Deadlock Avoidance  Deadlock.
Dr. Kalpakis CMSC 421, Operating Systems Deadlocks.
Deadlocks System Model RAG Deadlock Characterization
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 7: Deadlocks System Model Deadlock Characterization Methods.
Lecture 12 Handling Deadlock – Prevention, avoidance and detection.
Chapter 8 Deadlocks. Objective System Model Deadlock Characterization Methods for Handling Deadlocks Deadlock Prevention Deadlock Avoidance Deadlock Detection.
Chapter 7: Deadlocks. 7.2CSCI 380 – Operating Systems Chapter 7: Deadlocks The Deadlock Problem System Model Deadlock Characterization Methods for Handling.
7.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 7: Deadlocks The Deadlock Problem System Model Deadlock Characterization.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 7: Deadlocks The Deadlock Problem System Model Deadlock.
CS307 Operating Systems Deadlocks Fan Wu Department of Computer Science and Engineering Shanghai Jiao Tong University Spring 2012.
Chap 7 Deadlocks. Chapter Objectives To develop a description of deadlocks, which prevent sets of concurrent processes from completing their tasks To.
1 CS.217 Operating System By Ajarn..Sutapart Sappajak,METC,MSIT Chapter 6 Deadlocks Slide 1 Chapter 6 Deadlocks.
7.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Chapter 7: Deadlocks.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 7: Deadlocks The Deadlock Problem System Model Deadlock.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 7: Deadlocks The Deadlock Problem System Model Deadlock.
7.1 CSE Department MAITSandeep Tayal 7: Deadlocks System Model Deadlock Characterization Methods for Handling Deadlocks Deadlock Prevention Deadlock Avoidance.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts - 7 th Edition, Feb 14, 2005 Chapter 7: Deadlocks The Deadlock.
CSE Operating System Principles Deadlocks. CSE – Operating System Principles2 Overview System Model Deadlock Characterization Methods for.
Lecture 6 Deadlock 1. Deadlock and Starvation Let S and Q be two semaphores initialized to 1 P 0 P 1 wait (S); wait (Q); wait (Q); wait (S);. signal (S);
Chapter 7: Deadlocks. The Deadlock Problem System Model Deadlock Characterization Methods for Handling Deadlocks Deadlock Prevention Deadlock Avoidance.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 7: Deadlocks.
Chapter 7: Deadlocks.
OPERATING SYSTEM CONCEPTS AND PRACTISE
Chapter 7: Deadlocks.
G.Anuradha Ref:- Galvin
Chapter 7: Deadlocks.
Chapter 7 Deadlocks.
Process Deadlocks.
Deadlock B.Ramamurthy CSE421 1/11/2019 B.Ramamurthy.
G.Anuradha Ref:- Galvin
Chapter 7: Deadlocks.
Outline Deadlocks, dead lock prevention, avoidance.
Deadlock B.Ramamurthy CSE421 2/23/2019 B.Ramamurthy.
Chapter 7: Deadlocks.
Deadlock B.Ramamurthy CSE421 4/23/2019 B.Ramamurthy.
Deadlock B.Ramamurthy CSE421 5/1/2019 B.Ramamurthy.
Chapter 7: Deadlocks.
Chapter 7: Deadlocks.
Deadlock B.Ramamurthy CSE421 8/28/2019 B.Ramamurthy.
Deadlock B.Ramamurthy CSE421 9/3/2019 B.Ramamurthy.
Presentation transcript:

Process Management Deadlocks

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

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

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

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

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.

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)

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.

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

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

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

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)

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 .

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

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

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!

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

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

Resource Allocation Graph Vs. Wait-For Graph

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

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?

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

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

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

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