Lecture 29 Syed Mansoor Sarwar

Slides:



Advertisements
Similar presentations
Chapter 7: Deadlocks.
Advertisements

Washington WASHINGTON UNIVERSITY IN ST LOUIS Concurrency: Deadlock Detection Fred Kuhns Department.
Chapter 7: Deadlocks.
7.5 Deadlock Avoidance The algorithm is simply to ensure that the system will always remain in safe state. Therefore, if a process requests a resource.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 7: Deadlocks.
Chapter 7: Deadlocks (Continuation). 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts - 7 th Edition, Feb 14, 2005 Chapter 7: Deadlocks.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 30 Handling Deadlock.
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 Chapter 7: Deadlock. 2 The Deadlock Problem System Model Deadlock Characterization Methods for Handling Deadlocks Deadlock Prevention Deadlock Avoidance.
03/07/2007CSCI 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.
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.
03/03/2004CSCI 315 Operating Systems Design1 Deadlock Notice: The slides for this lecture have been largely based on those accompanying the textbook Operating.
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  Operating System Concepts Chapter 8: Deadlocks System Model Deadlock Characterization Methods for Handling Deadlocks.
Chapter 7: Deadlocks Adapted to COP4610 by Robert van Engelen.
System Model Deadlock Characterization Methods for Handling Deadlocks Deadlock Prevention, Avoidance, and Detection Recovering from Deadlock Combined Approach.
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
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 7: Deadlocks The Deadlock Problem System Model Deadlock.
 The Deadlock Problem  System Model  Deadlock Characterization  Methods for Handling Deadlocks  Deadlock Prevention  Deadlock Avoidance  Deadlock.
Dr. Kalpakis CMSC 421, Operating Systems Deadlocks.
1 Advanced Operating Systems - Spring 2009 Lecture 10 – February 11, 2009 Dan C. Marinescu Office: HEC 439 B. Office.
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.
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 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.
Deadlocks - System Model - Deadlock characterization - Methods for handling deadlocks - Deadlock prevention,avoidance - Deadlock detection and recovery.
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.
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.
Thursday, February 23, 2012 Chapter 6 homework questions?
Chapter 7: Deadlocks.
OPERATING SYSTEM CONCEPTS AND PRACTISE
Chapter 7: Deadlocks.
Deadlock Detection & recovery
G.Anuradha Ref:- Galvin
Chapter 7: Deadlocks.
Operating System: DEADLOCKS
Process Deadlocks.
Lecture 6: Deadlocks, Deadlock Risk Management
G.Anuradha Ref:- Galvin
Chapter 7: Deadlocks.
Outline Deadlocks, dead lock prevention, avoidance.
Deadlock Prevention Restrain the ways request can be made.
Deadlocks Session - 14.
Lecture 28 Syed Mansoor Sarwar
Chapter 7: Deadlocks.
Chapter 7: Deadlocks.
Chapter 7: Deadlocks.
OPERATING SYSTEM CONCEPTS
Presentation transcript:

Lecture 29 Syed Mansoor Sarwar Operating Systems Lecture 29 Syed Mansoor Sarwar

© Copyright Virtual University of Pakistan Agenda for Today Review of previous lecture Deadlock detection: resources with single and multiple instances Recovery from deadlocks Process termination Resource preemption Recap of lecture 12 January 2019 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Review of Lecture 28 Deadlock avoidance Resource with single instances Resources with multiple instances: Banker’s algorithm 12 January 2019 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Deadlock Detection Allow system to enter deadlock state Detection algorithm Recovery scheme 12 January 2019 © Copyright Virtual University of Pakistan

Single Instance of Each Resource Type Maintain a wait-for graph Nodes are processes. Pi  Pj if Pi is waiting for Pj. 12 January 2019 © Copyright Virtual University of Pakistan

Single Instance of Each Resource Type Periodically invoke an algorithm that searches for a cycle in the wait-for graph. The algorithm is expensive—it requires an order of n2 operations, where n is the number of vertices in the graph. 12 January 2019 © Copyright Virtual University of Pakistan

RAG and Wait-for Graph Resource-Allocation Graph 12 January 2019 © Copyright Virtual University of Pakistan Resource-Allocation Graph Corresponding wait-for graph

Multiple Instance of Each Resource Type Available: A vector of length m indicates the number of available resources of each type. Allocation: An n x m matrix defines the number of resources of each type currently allocated to each process. 12 January 2019 © Copyright Virtual University of Pakistan

Multiple Instance of Each Resource Type Request: An n x m matrix indicates the current request of each process. If Request[i,j]=k, then process Pi is requesting k more instances of resource type. Pj. 12 January 2019 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Detection Algorithm Let Work and Finish be vectors of length m and n, respectively Initialize: Work = Available; for i = 1, 2, …, n if Allocationi  0 then Finish[i] = false; else Finish[i] = true; 12 January 2019 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Detection Algorithm Find an index i such that both: (a) Finish[i] == false (b) Requesti  Work If no such i exists, go to step 4. 12 January 2019 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Detection Algorithm Work = Work + Allocationi Finish[i] = true go to step 2. If Finish[i] == false, for some i, 1  i  n, then the system is in deadlock state. Moreover, if Finish[i] == false, then Pi is deadlocked. 12 January 2019 © Copyright Virtual University of Pakistan

Example of Detection Algorithm Consider the following system: P = { P0, P1, P2, P3, P4 } R = { A, B, C } A: 7 instances B: 2 instances C: 6 instances 12 January 2019 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Example System State Process P0 P1 P2 P3 P4 Allocation A B C 0 1 0 2 0 0 3 0 2 2 1 1 0 0 2 Request A B C 0 0 0 2 0 2 1 0 0 0 0 2 Work A B C Finish Sequence: <> 12 January 2019 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Example System State Process P0 P1 P2 P3 P4 Allocation A B C 0 1 0 2 0 0 3 0 2 2 1 1 0 0 2 Request A B C 0 0 0 2 0 2 1 0 0 0 0 2 Work A B C 1 Finish Sequence: <P0> 12 January 2019 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Example System State Process P0 P1 P2 P3 P4 Allocation A B C 0 1 0 2 0 0 3 0 2 2 1 1 0 0 2 Request A B C 0 0 0 2 0 2 1 0 0 0 0 2 Work A B C 1 3 2 Finish Sequence: <P0, P2> 12 January 2019 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Example System State Process P0 P1 P2 P3 P4 Allocation A B C 0 1 0 2 0 0 3 0 2 2 1 1 0 0 2 Request A B C 0 0 0 2 0 2 1 0 0 0 0 2 Work A B C 1 3 2 5 Finish Sequence: < P0, P2, P3> 12 January 2019 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Example System State Process P0 P1 P2 P3 P4 Allocation A B C 0 1 0 2 0 0 3 0 2 2 1 1 0 0 2 Request A B C 0 0 0 2 0 2 1 0 0 0 0 2 Work A B C 1 3 2 5 Finish Sequence: < P0, P2, P3, P4 > 12 January 2019 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Example System State Final finish sequence: < P0, P2, P3, P4 , P1 > Other possible finish sequences: < P0, P2, P3, P1 , P4 > < P0, P2, P4, P1 , P3 > < P0, P2, P4, P3 , P1 > … 12 January 2019 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Example System State P2 requests an additional instance of C. Do we have a finish sequence? Process P0 P1 P2 P3 P4 Request A B C 0 0 0 2 0 2 0 0 1 1 0 0 0 0 2 12 January 2019 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Example System State Process P0 P1 P2 P3 P4 Allocation A B C 0 1 0 2 0 0 3 0 2 2 1 1 0 0 2 Request A B C 0 0 0 2 0 2 0 0 1 1 0 0 0 0 2 Work A B C Finish Sequence: <> 12 January 2019 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Example System State Process P0 P1 P2 P3 P4 Allocation A B C 0 1 0 2 0 0 3 0 2 2 1 1 0 0 2 Request A B C 0 0 0 2 0 2 0 0 1 1 0 0 0 0 2 Work A B C 1 Finish Sequence: <P0> 12 January 2019 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Example System State P0’s request can be satisfied with currently available resources, but request for no other process can be satisfied after that.  Deadlock exists, consisting of processes P1, P2, P3, and P4. 12 January 2019 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Detection Algorithm How often should the detection algorithm be invoked? Every time a request for allocation cannot be granted immediately—expensive but process causing the deadlock is identified, along with processes involved in deadlock 12 January 2019 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Detection Algorithm Periodically, or based on CPU utilization Arbitrarily—there may be many cycles in the resource graph and we would not be able to tell which of the many deadlocked processes “caused” the deadlock. 12 January 2019 © Copyright Virtual University of Pakistan

Recovery from Deadlock: Process Termination Abort all deadlocked processes. Abort one process at a time until the deadlock cycle is eliminated. 12 January 2019 © Copyright Virtual University of Pakistan

Recovery from Deadlock: Process Termination In which order should we choose to abort processes? Priority of a process. How long the process has computed, and how much longer to completion. 12 January 2019 © Copyright Virtual University of Pakistan

Recovery from Deadlock: Process Termination Resources the process has used. Resources the process needs to complete. How many processes will need to be terminated. Is the process interactive or batch? 12 January 2019 © Copyright Virtual University of Pakistan

Recovery from Deadlock: Resource Preemption Selecting a victim – minimize cost. Rollback – return to some safe state, restart process from that state. Starvation – same process may always be picked as victim; include number of rollbacks in cost factor. 12 January 2019 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Recap of Lecture Deadlock detection Recovery from deadlock Process termination Resource preemption 12 January 2019 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Operating Systems Lecture 29 Syed Mansoor Sarwar 12 January 2019 © Copyright Virtual University of Pakistan