Deadlocks References text: Tanenbaum ch.3.

Slides:



Advertisements
Similar presentations
Deadlocks Today Resources & deadlocks Dealing with deadlocks Other issues Next Time Memory management.
Advertisements

MODERN OPERATING SYSTEMS Third Edition ANDREW S
Ceng Operating Systems Chapter 2.4 : Deadlocks Process concept  Process scheduling  Interprocess communication  Deadlocks Threads.
Chapter 3 Deadlocks TOPICS Resource Deadlocks The ostrich algorithm
MODERN OPERATING SYSTEMS Third Edition ANDREW S. TANENBAUM Chapter 6 Deadlocks Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All.
1 Deadlocks Chapter Resource 3.2. Introduction to deadlocks 3.3. The ostrich algorithm 3.4. Deadlock detection and recovery 3.5. Deadlock avoidance.
Tanenbaum Ch 6 Silberschatz Ch 7
5/25/2015Page 1 Deadlock Management B. Ramamurthy.
1 CSE 380 Computer Operating Systems Instructor: Insup Lee and Dianna Xu University of Pennsylvania, Fall 2003 Lecture Note: Deadlocks.
Chapter 3 Deadlocks - Αδιέξοδα 3.1. Resource
With slides from C. Griwodz, K. Li, A. Tanenbaum and M. van Steen
Avishai Wool lecture Introduction to Systems Programming Lecture 5 Deadlocks.
Deadlock Chapter 3 R1 R2 P2P1 Allocated Requested.
Deadlocks Tore Larsen With slides from T. Plagemann, C. Griwodz, K. Li, A. Tanenbaum and M. van Steen.
Mehdi Naghavi Spring 1386 Operating Systems Mehdi Naghavi Spring 1386.
Chapter 3: Deadlocks Chapter 3 2 CMPS 111, UC Santa Cruz Overview  Resources  Why do deadlocks occur?  Dealing with deadlocks Ignoring them: ostrich.
Deadlocks. 2 System Model There are non-shared computer resources –Maybe more than one instance –Printers, Semaphores, Tape drives, CPU Processes need.
Deadlock CSCI 444/544 Operating Systems Fall 2008.
Chapter 3 Deadlocks 3.1. Resource 3.2. Introduction to deadlocks
Deadlock Detection with One Resource of Each Type (1)
Chapter 6 Deadlocks Resources Introduction Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved
Chapter 3 Chapter 3: Deadlocks Chapter 3 2 CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt) Overview Resources Why do.
Deadlocks.
Deadlock Chapter 3 Thursday, February 22, Today’s Schedule Assignment #4 from Chapter 3 posted Deadlock - Chapter 3  Skip multiple resources (3.4.2.
CH 3 Deadlock When 2 (or more) processes remain blocked forever!
1 Deadlocks Chapter Resource 3.2. Introduction to deadlocks 3.3. The ostrich algorithm 3.4. Deadlock detection and recovery 3.5. Deadlock avoidance.
Chapter 3: Deadlocks. CMPS 111, Fall Overview ✦ Resources ✦ Why do deadlocks occur? ✦ Dealing with deadlocks Ignoring them: ostrich algorithm Detecting.
Overview Resources Why do deadlocks occur? Dealing with deadlocks Ignoring them: ostrich algorithm Detecting & recovering from deadlock Avoiding deadlock.
1 Deadlocks Chapter Resource 3.2. Introduction to deadlocks 3.4. Deadlock detection and recovery 3.5. Deadlock avoidance 3.6. Deadlock prevention.
1 Deadlocks 2 Resources Examples of computer resources –printers –tape drives –tables Processes need access to resources in reasonable order Suppose.
1 Deadlocks Chapter Resource 3.2. Introduction to deadlocks 3.3. The ostrich algorithm 3.4. Deadlock detection and recovery 3.5. Deadlock avoidance.
1 Deadlocks Chapter 3. 2 Resources Examples of computer resources –printers –tape drives –tables Processes need access to resources in reasonable order.
Operating Systems 软件学院 高海昌 Operating Systems Gao Haichang, Software School, Xidian University 22 Contents  1. Introduction** 
1 Deadlock Definition of deadlock Condition for its occurrence Solutions for avoiding and breaking deadlock –Deadlock Prevention –Deadlock Avoidance –Deadlock.
1 Deadlocks Chapter Resource 3.2. Introduction to deadlocks 3.3. The ostrich algorithm 3.4. Deadlock detection and recovery 3.5. Deadlock avoidance.
Operating Systems (OS)
1 MODERN OPERATING SYSTEMS Third Edition ANDREW S. TANENBAUM Chapter 6 Deadlocks Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc.
MODERN OPERATING SYSTEMS Third Edition ANDREW S. TANENBAUM Chapter 6 Deadlocks Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All.
Deadlocks. What is a Deadlock “A set of processes is deadlocked if each process in the set is waiting for an event that only another process in the set.
CSC 322 Operating Systems Concepts Lecture - 28: by Ahmed Mumtaz Mustehsan Special Thanks To: Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall,
CS333 Intro to Operating Systems Jonathan Walpole.
CH 3 Deadlock When 2 (or more) processes remain blocked forever!
Copyright ©: Nahrstedt, Angrave, Abdelzaher1 Deadlock.
Deadlocks References –text: Tanenbaum ch.3. Deadly Embrace Deadlock definition –A set of process is dead locked if each process in the set is waiting.
Deadlocks Chapter 6 Tanenbaum & Bo, Modern Operating Systems:4th ed., (c) 2013 Prentice-Hall, Inc. All rights reserved.
Sistem Operasi IKH311 Deadlock. 2 Resources Examples of computer resources printers tape drives tables Processes need access to resources in reasonable.
Deadlocks Lots of resources can only be used by one process at a time. Exclusive access is needed. Suppose process A needs R1 + R2 and B needs R1 + R2.
Operating Systems Chapter 3: Deadlocks
FAA FAA (int s, int val) { temp = s; s = s + val; return temp; }
MODERN OPERATING SYSTEMS Third Edition ANDREW S
Deadlock Management.
ITEC 202 Operating Systems
Chapter 6 : Deadlocks What is a Deadlock?
Deadlocks References text: Tanenbaum ch.3.
Lecture 18: Deadlock: Conditions, Detection and Avoidance (cont.)
Lecture 19: Deadlock: Conditions, Detection and Avoidance
Chapter 7: Deadlocks.
Deadlocks Definition A set of processes is in a Deadlock state when every process in the set is waiting for an event that can only be caused by another.
Chapter 3 Deadlocks 3.1. Resource 3.2. Introduction to deadlocks
DPNM Lab. Dept. of CSE, POSTECH
MODERN OPERATING SYSTEMS Third Edition ANDREW S
Chapter 3 Deadlocks 3.1. Resource 3.2. Introduction to deadlocks
DEADLOCK.
Lecture 19: Deadlock: Conditions, Detection and Avoidance
Chapter 3 Deadlocks 3.1. Resource 3.2. Introduction to deadlocks
Introduction to Deadlocks
Chapter 3 Deadlocks 3.1. Resource 3.2. Introduction to deadlocks
Deadlocks References text: Tanenbaum ch.3.
MODERN OPERATING SYSTEMS Third Edition ANDREW S
Chapter 3 Deadlocks -For MCA, PU
Presentation transcript:

Deadlocks References text: Tanenbaum ch.3

Deadly Embrace Deadlock definition Example A set of process is dead locked if each process in the set is waiting for an event that only another process in the set can cause Example

Necessary Conditions for Deadlock 1. Mutual exclusion only 1 process has access to the resource at a time 2. Hold and wait process currently holding resources can request new ones 3. No resource preemption resources granted cannot be forcibly taken way from a process 4. Circular wait a circular chain each of which is waiting for a resource held by the next member of the chain

Deadlock Modeling Modeling with directed graphs-Resource Allocation Graphs resource R assigned to process A process B is requesting/waiting for resource S process C and D are in deadlock over resources T and U

Strategies for dealing with Deadlocks just ignore the problem altogether detection and recovery dynamic avoidance careful resource allocation prevention negating one of the four necessary conditions

How Deadlock Occurs

How Deadlock can be Avoided

Deadlock Detection and Recovery Detection with One Resource of Each type (e.g. 1 printer, 1 disk) Construct the resource allocation graph and look for cycles. Any process that is part of a cycle is deadlocked. D, E, G are deadlocked T

Algorithm to Detect Deadlocks Loop for each node in graph, initialize L=[], arcs unmarked L: data structure of a list of nodes Add current node to L Current node = last node Node appears twice? last node= initial node? yes Any unmarked outgoing arc? yes Mark the arc and follow it to next node yes Found deadlock Found no deadlock End End Remove the node from L

Example From node R From node B L=[] L=[], L=[B],... L=[R] L=[B,T,E,V,G,U,D] L=[R,A,S] L=[B,T,E,V,G,U,D,S] L=[R,A] L=[B,T,E,V,G,U,D] L=[R] L=[B,T,E,V,G,U,D,T] no deadlock from R found deadlock

Deadlock Detection and Recovery (cont’d) Detection with Multiple Resource of Each Type (e.g. 2 printers etc) n Cij +Aj = Ej i=1

Algorithm to Detect Deadlocks Go through every unmarked process, for ith process Mark process yes A = A + Ci Ri < A ? Pick another process Deadlock occurs if there are unmarked processes end Vector comparison: Ri < A means for all j, Rij < Aj

Deadlock Detection Example Vector comparison Ri < A processes 1 and 2 cannot be satisfied process 3 is satisfied and A is updated A=A + C3 =(2 2 2 0) process 1 cannot be satisfied, but process 2 is satisfied. A is updated to A=(4 2 2 1) process 1 can be satisfied and there is no deadlock in system

Deadlock Recovery Through Preemption Through Rollback take a resource from some other process depends on nature of the resource Through Rollback checkpoint a process periodically use this saved state restart the process if it is found deadlocked Through Killing Processes crudest but simplest way to break a deadlock kill one of the processes in the deadlock cycle the other processes get its resources choose process that can be rerun from the beginning

Deadlock Avoidance Safe and Unsafe States A safe state is not deadlocked and there is some scheduling order that every process can run to completion Safe state example (10 available instances of a resource) Unsafe state example (10 available instances of a resource)

Banker’s Algorithm Check to see if granting the request for a resource leads to an unsafe state. If it does, the request is denied. A single resource example: Unsafe Safe Safe Schedule order: A, B, C, D C, B, A, D Cannot schedule any task

Banker’s Algorithm for Multiple Resources E: existing P: possessed A: available “C” “R” (Current allocation) (Remaining Needs) Use the same deadlock detection algorithm Ri < A, if true, A = A + Ci

Banker’s Algorithm for Multiple Resources (cont’d) 4 5 3 E: existing P: possessed A: available 1 2 “C” “R” (Current allocation) (Remaining Needs) Start Process D. After completion, P=(4,2,2,1), A=(2,1,2,1) Start Process E. After completion, P=(4,2,2,1), A=(2,1,2,1) Start Process C. After completion, P=(3,1,1,1), A=(3,2,3,1) Start Process A. After completion, P=(0,1,0,0), A=(6,2,4,2) Start Process B. After completion, P=(0,0,0,0), A=(6,3,4,2) A safe state No deadlock

Deadlock Prevention Attack the mutual exclusion condition use spooling Attack the hold and wait condition request all resources initially Attack the no preemption take resources away Attack the circular wait condition order resources numerically