Slide 10-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10.

Slides:



Advertisements
Similar presentations
Chapter 7: Deadlocks.
Advertisements

Slide 10-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10.
ICS Principles of Operating Systems Lectures 8 and 9 - Deadlocks Prof. Dmitri V. Kalashnikov dvk ics.uci.edu Slides © Prof. Nalini Venkatasubramanian.
Concurrency: Deadlock and Starvation Chapter 6. Deadlock Permanent blocking of a set of processes that either compete for system resources or communicate.
Operating Systems Lecture Notes Deadlocks Matthew Dailey Some material © Silberschatz, Galvin, and Gagne, 2002.
MODERN OPERATING SYSTEMS Third Edition ANDREW S
Chapter 7: Deadlocks.
Chapter 81 Deadlock is:  A set of blocked processes each holding a resource and waiting to acquire a resource held by another process in the set.  Example.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 7: Deadlocks.
1 CSC 539: Operating Systems Structure and Design Spring 2005 Process deadlock  deadlock prevention  deadlock avoidance  deadlock detection  recovery.
© 2004, D. J. Foreman 1 Deadlock. © 2004, D. J. Foreman 2 Example  P1 requests most of real memory  Disk block mgr is swapped out ot make room for P1's.
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.
10 Deadlock Example Process 1 Process 2 Resource 1 Resource 2 Process holds the resource Process requests the resource.
Chapter 7: Deadlocks. 7.2 Chapter Objectives To develop a description of deadlocks, which prevent sets of concurrent processes from completing their tasks.
Deadlock CSCI 444/544 Operating Systems Fall 2008.
The ‘deadlock’ conditions Reviewing some key points concerning the potential for ‘deadlock’ in an operating system.
1 Lecture 8: Deadlocks Operating System Spring 2008.
OS Spring 2004 Concurrency: Principles of Deadlock Operating Systems Spring 2004.
OS Fall’02 Concurrency: Principles of Deadlock Operating Systems Fall 2002.
02/19/2008CSCI 315 Operating Systems Design1 Deadlock Notice: The slides for this lecture have been largely based on those accompanying the textbook Operating.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts - 7 th Edition, Feb 14, 2005 Chapter 7: Deadlocks The Deadlock.
Deadlock. Example Process 1 Process 2 Resource 1 Resource 2.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 7: Deadlocks.
Deadlocks Gordon College Stephen Brinton. Deadlock Overview The Deadlock Problem System Model Deadlock Characterization Methods for Handling Deadlocks.
What we will cover…  The Deadlock Problem  System Model  Deadlock Characterization  Methods for Handling Deadlocks  Deadlock Prevention  Deadlock.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Deadlocks.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 7: Deadlocks Modified.
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
 The Deadlock Problem  System Model  Deadlock Characterization  Methods for Handling Deadlocks  Deadlock Prevention  Deadlock Avoidance  Deadlock.
Dr. Kalpakis CMSC 421, Operating Systems Deadlocks.
CS 346 – Chapter 7 Deadlock –Properties –Analysis: directed graph Handle –Prevent –Avoid Safe states and the Banker’s algorithm –Detect –Recover.
Deadlocks System Model RAG Deadlock Characterization
Styresystemer og Multiprogrammering Block 3, 2005 Deadlocks Robert Glück.
Lecture 12 Handling Deadlock – Prevention, avoidance and detection.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 7: Deadlocks.
Copyright © 2006 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill Technology Education Lecture 7 Operating Systems.
Operating Systems Unit VI Deadlocks and Protection Department of Computer Science Engineering and Information Technology.
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.
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.
1 CS.217 Operating System By Ajarn..Sutapart Sappajak,METC,MSIT Chapter 6 Deadlocks Slide 1 Chapter 6 Deadlocks.
Deadlocks 12/02/2015. What is a deadlock ? System has a finite set of resources. Resource can have one or more instances. Processes compete for resources.
Deadlocks Copyright ©: University of Illinois CS 241 Staff1.
Slide 10-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10.
Silberschatz, Galvin and Gagne ©2009 Edited by Khoury, 2015 Operating System Concepts – 9 th Edition, Chapter 7: Deadlocks.
Copyright ©: Nahrstedt, Angrave, Abdelzaher1 Deadlock.
Slide 10-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10.
2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process.
Deadlock. Examples You can't get a job without experience; you can't get experience without a job. A set of blocked processes each holding a resource.
Process Management Deadlocks.
CSE 120 Principles of Operating
Concurrency: Deadlock and Starvation
ITEC 202 Operating Systems
ICS 143 Principles of Operating Systems
Outline Announcement Deadlock Deadlock definition - review
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.
Banker`s Algorithm Developed by Dijkstra in 1965
CSc 552 Advanced Unix Process deadlock deadlock prevention
Deadlocks Peng Lu In a multiprogramming environment, several processes may compete for a finite number of resources. A process requests resources; if the.
DEADLOCK.
Deadlock © 2004, D. J. Foreman.
CSCI 315 Operating Systems Design
Presentation transcript:

Slide 10-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10

Slide 10-2 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter Deadlock

Slide 10-3 Copyright © 2004 Pearson Education, Inc. deadlock cooperating processes are processes that cooperate to achieve a specific task. Multiple cooperating processes introduce the potential for new synchronization problems in software implementation –Critical section –deadlock Operating Systems: A Modern Perspective, Chapter 10

Slide 10-4 Copyright © 2004 Pearson Education, Inc. Real life eg:Automobile gridlock Operating Systems: A Modern Perspective, Chapter 10

Slide 10-5 Copyright © 2004 Pearson Education, Inc. gridlock Operating Systems: A Modern Perspective, Chapter 10

Slide 10-6 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10 Example: computer science Process 1 Process 2 Resource 1 Resource 2 Process holds the resource Process requests the resource

Slide 10-7 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10 Three Deadlocked Processes Process 1 Process 2 Process 3 Resource 1 Resource 2 Resource 3 Process holds the resource Process requests the resource

Slide 10-8 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10 Addressing Deadlock Prevention: Design the system so that deadlock is impossible Avoidance: Construct a model of system states, then choose a strategy that will not allow the system to go to a deadlock state Detection & Recovery: Check for deadlock (periodically or sporadically), then recover

Slide 10-9 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10 Prevention Necessary conditions for deadlock –Mutual exclusion –Hold and wait –Circular waiting –No preemption Ensure that at least one of the necessary conditions is false at all times –Mutual exclusion must hold at all times

Slide Copyright © 2004 Pearson Education, Inc. Consider automobile grid lock: each section of the street as a resource Mutual exclusion condition applies, since only one vehicle can be on a section of the street at a time. Hold-and-wait condition applies, since each vehicle is occupying a section of the street, and waiting to move on to the next section of the street. No-preemptive condition applies, since a section of the street that is a section of the street that is occupied by a vehicle cannot be taken away from it. Circular wait condition applies, since each vehicle is waiting on the next vehicle to move. That is, each vehicle in the traffic is waiting for a section of street held by the next vehicle in the traffic. Operating Systems: A Modern Perspective, Chapter 10

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10 Hold and Wait Need to be sure a process does not hold one resource while requesting another Approach 1: Force a process to request all resources it needs at one time Approach 2: If a process needs to acquire a new resource, it must first release all resources it holds, then reacquire all it needs

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10 Circular Wait Have a situation in which there are K processes holding units of K resources RP RP P holds R P requests R RiRi PiPi

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10 Allowing Preemption Allow a process to time-out on a blocked request -- withdrawing the request if it fails SiSi ruru dvdv ruru SjSj SkSk wuwu

Slide Copyright © 2004 Pearson Education, Inc. Avoidance Define a model of system states, then choose a strategy that will guarantee that the system will not go to a deadlock state Avoidance strategies are a conservative approach to resource allocation. The strategy is to analyze a prospective state – before entering it – to guarantee that every process can still execute. Operating Systems: A Modern Perspective, Chapter 10

Slide Copyright © 2004 Pearson Education, Inc. Avoidance It relies on resource manager’s ability to predict the effect of satisfying individual allocation requests. –If a request can lead a situation in which a deadlock could occur, avoidance strategy will refuse the request. –It is a predictive approach which relies on the information about the resource activity that will be occurring for the process Maximum claim Operating Systems: A Modern Perspective, Chapter 10

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10 Safe vs Unsafe States Safe state: one in which the system can assure that any sequence of subsequent transitions leads back to the initial state –Even if all exercise their maximum claim, there is an allocation strategy by which all claims can be met Unsafe state: one in which the system cannot guarantee that the system will transition back to the initial state –Unsafe state can lead to a deadlock state if too many processes exercise their maximum claim at once

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10 More on Safe & Unsafe States I Safe States Unsafe States Deadlock States Disallow

Slide Copyright © 2004 Pearson Education, Inc. Banker’s algorithm The banker’s algorithm is the classic avoidance strategy. It is modeled after the lending policies employed in banking systems –A bank has a limited amount of funds(resources) that can be lent to different borrowers(processes) –To accommodate borrowers, the bank may extent a line of credit(pre-approved limit) to a customer –Line of credit is a maximum claim for resources by the customer Operating Systems: A Modern Perspective, Chapter 10

Slide Copyright © 2004 Pearson Education, Inc. At any moment loan department looks at the funds allocated to all customers and the maximum amount that can be requested by each customer. If there is some sequence of activity in which at least one customer’s full line of credit can be met, assume that the customer can borrow up to the line of credit and then repay the entire loan. After this customer has repaid the loan, the algorithm iterates on the other accounts If all customers can exercise their lines of credit and repay their loans, then the current state is safe. Operating Systems: A Modern Perspective, Chapter 10

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10 Avoidance This strategy depends on additional information about the long-term resource needs of each process. In particular, when a process is created, it must declare its maximum claim - the maximum number of units it will ever request – to every resource type. The resource manager can honor the request if the resources are available

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10 Banker’s Algorithm Let maxc[i, j] be the maximum claim for R j by p i Let alloc[i, j] be the number of units of R j held by p i Can always compute –avail[j] = c j -  0  i  n alloc[i,j] –Then number of available units of R j Should be able to determine if the state is safe or not using this info

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10 Banker’s Algorithm Copy the alloc[i,j] table to alloc’[i,j] Given C, maxc and alloc’, compute avail vector Find p i : maxc[i,j] - alloc’[i,j]  avail[j] for 0  j < m and 0  i < n. –If no such p i exists, the state is unsafe –If alloc’[i,j] is 0 for all i and j, the state is safe Set alloc’[i,j] to 0; deallocate all resources held by p i ; go to Step 2

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10 Example ProcessR 0 R 1 R 2 R 3 p p p p p Maximum Claim ProcessR 0 R 1 R 2 R 3 p p p p p Sum7375 Allocated Resources C = Compute total allocated Determine available units avail = = Can anyone’s maxc be met? maxc[2,0]-alloc’[2,0] = 5-4 = 1  1 = avail[0] maxc[2,1]-alloc’[2,1] = 1-0 = 1  2 = avail[1] maxc[2,2]-alloc’[2,2] = 0-0 = 0  2 = avail[2] maxc[2,3]-alloc’[2,3] = 5-3 = 2  2 = avail[3] P 2 can exercise max claim avail[0] = avail[0]+alloc’[2,0] = 1+4 = 5 avail[1] = avail[1]+alloc’[2,1] = 2+0 = 2 avail[2] = avail[2]+alloc’[2,2] = 2+0 = 2 avail[3] = avail[3]+alloc’[2,3] = 2+3 = 5

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10 Example ProcessR 0 R 1 R 2 R 3 p p p p p Maximum Claim ProcessR 0 R 1 R 2 R 3 p p p p p Sum3372 Allocated Resources C = Compute total allocated Determine available units avail = = Can anyone’s maxc be met? maxc[4,0]-alloc’[4,0] = 3-1 = 4  5 = avail[0] maxc[4,1]-alloc’[4,1] = 0-0 = 0  2 = avail[1] maxc[4,2]-alloc’[4,2] = 3-3 = 0  2 = avail[2] maxc[4,3]-alloc’[4,3] = 3-0 = 3  5 = avail[3] P 4 can exercise max claim avail[0] = avail[0]+alloc’[4,0] = 5+1 = 6 avail[1] = avail[1]+alloc’[4,1] = 2+0 = 2 avail[2] = avail[2]+alloc’[4,2] = 2+3 = 5 avail[3] = avail[3]+alloc’[4,3] = 5+0 = 5

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10 Example ProcessR 0 R 1 R 2 R 3 p p p p p Maximum Claim ProcessR 0 R 1 R 2 R 3 p p p p p Sum2142 Allocated Resources C = Compute total allocated Determine available units avail = = Can anyone’s maxc be met? (Yes, any of them can)

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10 Detection & Recovery Check for deadlock (periodically or sporadically), then recover Can be far more aggressive with allocation No maximum claim, no safe/unsafe states Differentiate between –Serially reusable resources: A unit must be allocated before being released –Consumable resources: Never release acquired resources; resource count is number currently available

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10 Recovery No magic here –Choose a blocked resource Preempt it (releasing its resources) Run the detection algorithm Iterate if until the state is not a deadlock state –May use resource graph to select processes to destroy. –Operator simply begins destroying processes untill the system appears to be operational again –Brute force is to reboot the entire machine