Lecture 28 Syed Mansoor Sarwar

Slides:



Advertisements
Similar presentations
Deadlock 2.
Advertisements

Chapter 7: Deadlocks.
Lecture 11 “Banker ’ s algorithm”.  Multiple instances.  Each process must a priori knowledge claim maximum use.  When 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.
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.
03/07/2007CSCI 315 Operating Systems Design1 Deadlock Notice: The slides for this lecture have been largely based on those accompanying the textbook Operating.
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.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 7: Deadlocks.
03/03/2004CSCI 315 Operating Systems Design1 Deadlock Notice: The slides for this lecture have been largely based on those accompanying the textbook Operating.
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.
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.
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.
 The Deadlock Problem  System Model  Deadlock Characterization  Methods for Handling Deadlocks  Deadlock Prevention  Deadlock Avoidance  Deadlock.
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.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 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.
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.
Deadlock A deadlock is a situation wherein two or more competing actions are waiting for the other to finish, and thus neither ever does. Example : “When.
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
CSSE 332 Operating Systems Rose-Hulman Institute of Technology
Chapter 7: Deadlocks.
Operating System Concepts
ICS Principles of Operating Systems
G.Anuradha Ref:- Galvin
Chapter 7: Deadlocks.
Chapter 3 Deadlocks 3.1. Resource 3.2. Introduction to deadlocks
Deadlock B.Ramamurthy CSE421 1/11/2019 B.Ramamurthy.
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 29 Syed Mansoor Sarwar
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.
CSCI 315 Operating Systems Design
Chapter 7: Deadlocks.
Banker’s Algorithm Anawil
Chapter 7: Deadlocks.
OPERATING SYSTEM CONCEPTS
Deadlock B.Ramamurthy CSE421 8/28/2019 B.Ramamurthy.
Deadlock B.Ramamurthy CSE421 9/3/2019 B.Ramamurthy.
Presentation transcript:

Lecture 28 Syed Mansoor Sarwar Operating Systems Lecture 28 Syed Mansoor Sarwar

© Copyright Virtual University of Pakistan Agenda for Today Review of previous lecture Deadlock avoidance Banker’s algorithms Safety algorithm Safe Sequence Recap of lecture 12 January 2019 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Review of Lecture 27 Deadlock handling Deadlock prevention Deadlock avoidance 12 January 2019 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan RAG Algorithm Claim edge Pi  Rj indicates that process Pi may request an instance of resource Rj; represented by a dashed line. Claim edge converts to request edge when a process requests a resource. 12 January 2019 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan RAG Algorithm When a resource is assigned to a process, request edge reconverts to an assignment edge. When a resource is released by a process, assignment edge reconverts to a claim edge. Resources must be claimed a priori in the system. 12 January 2019 © Copyright Virtual University of Pakistan

RAG For Deadlock Avoidance 12 January 2019 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Unsafe State In RAG 12 January 2019 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Banker’s Algorithm Multiple instances of resources. Each process must a priori claim maximum use. When a process requests a resource it may have to wait. When a process gets all its resources it must return them in a finite amount of time. 12 January 2019 © Copyright Virtual University of Pakistan

Data Structures for the Banker’s Algorithm n = number of processes m = number of resource types Available: Vector of length m. If available[j] = k, there are k instances of resource type Rj available. 12 January 2019 © Copyright Virtual University of Pakistan

Data Structures for the Banker’s Algorithm Max: n x m matrix. If Max[i,j] = k, then process Pi may request at most k instances of resource type Rj. Allocation: n x m matrix. If Allocation[i,j] = k then Pi is currently allocated k instances of Rj. 12 January 2019 © Copyright Virtual University of Pakistan

Data Structures for the Banker’s Algorithm Need: n x m matrix. If Need[i,j] = k, then Pi may need k more instances of Rj to complete its task. Need[i,j] = Max[i,j] – Allocation [i,j] 12 January 2019 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Safety Algorithm Let Work and Finish be vectors of length m and n, respectively. Initialize: Work = Available Finish[i] = false; i = 1, 2, …, n. 12 January 2019 © Copyright Virtual University of Pakistan

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

© Copyright Virtual University of Pakistan Safety Algorithm Work = Work + Allocationi Finish[i] = true go to step 2. If Finish [i] == true for all i, then the system is in a safe state. 12 January 2019 © Copyright Virtual University of Pakistan

Resource-Request Algorithm for Pi Requesti = request vector for Pi. If Requesti [j] = k then process Pi wants k instances of resource type Rj. If Requesti  Needi go to step 2. Otherwise, report error since process has exceeded its maximum claim. 12 January 2019 © Copyright Virtual University of Pakistan

Resource-Request Algorithm for Pi If Requesti  Available, go to step 3. Otherwise Pi must wait, since resources are not available. Pretend to allocate requested resources to Pi by modifying the state as follows: 12 January 2019 © Copyright Virtual University of Pakistan

Resource-Request Algorithm for Pi Available = Available – Requestj; Allocationi = Allocationi + Requesti; Needi = Needi – Requesti; If safe  the resources are allocated to Pi. If unsafe  Pi must wait, and the old resource-allocation state is restored 12 January 2019 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Example System Five processes: P0 … P4 Three resource types: A (10 instances) B (5 instances) C (7 instances) 12 January 2019 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Example System System state: Is it safe? Process P0 P1 P2 P3 P4 Max A B C 7 5 3 3 2 2 9 0 2 2 2 2 4 3 3 Allocation A B C 0 1 0 2 0 0 3 0 2 2 1 1 0 0 2 Available A B C 3 2 12 January 2019 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Example System Needi = Maxi – Allocationi Need matrix Process A B C P0 7 4 3 P1 1 2 P2 6 P3 P4 12 January 2019 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Example System Process P0 P1 P2 P3 P4 Need A B C 7 4 3 1 2 2 6 0 0 0 1 1 4 3 1 Allocation A B C 0 1 0 2 0 0 3 0 2 2 1 1 0 0 2 Work A B C 3 2 Safe Sequence: <> 12 January 2019 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Example System Process P0 P1 P2 P3 P4 Need A B C 7 4 3 1 2 2 6 0 0 0 1 1 4 3 1 Allocation A B C 0 1 0 2 0 0 3 0 2 2 1 1 0 0 2 Work A B C 3 2 5 Safe Sequence: < P1> 12 January 2019 © Copyright Virtual University of Pakistan

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

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

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

© Copyright Virtual University of Pakistan Example System Final safe sequence: <P1, P3, P4, P0, P2> Not a unique sequence Possible safe sequences for the this example: <P1,P3,P4,P0,P2>, <P1,P3,P4,P2,P0>, <P1,P3,P2,P0,P4>, <P1,P3,P2,P4,P0>, <P1,P3,P0,P2,P4>, <P1,P3,P0,P4,P2> 12 January 2019 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Example P1 requests (1,0,2). Can this request be granted immediately? Is Request1  Need1? (1,0,2)  (1,2,2)  true Is Request1  Available? (1,0,2)  (3,3,2)  true 12 January 2019 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Example Process P0 P1 P2 P3 P4 Need A B C 7 4 3 1 2 2 6 0 0 0 1 1 4 3 1 Allocation A B C 0 1 0 2 0 0 3 0 2 2 1 1 0 0 2 Available A B C 3 2 12 January 2019 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Example Process P0 P1 P2 P3 P4 Need A B C 7 4 3 0 2 0 6 0 0 0 1 1 4 3 1 Allocation A B C 0 1 0 3 0 2 2 1 1 0 0 2 Work A B C 2 3 Safe Sequence: <> 12 January 2019 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Example Process P0 P1 P2 P3 P4 Need A B C 7 4 3 0 2 0 6 0 0 0 1 1 4 3 1 Allocation A B C 0 1 0 3 0 2 2 1 1 0 0 2 Work A B C 2 3 5 Safe Sequence: < P1 > 12 January 2019 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Example Process P0 P1 P2 P3 P4 Need A B C 7 4 3 0 2 0 6 0 0 0 1 1 4 3 1 Allocation A B C 0 1 0 3 0 2 2 1 1 0 0 2 Work A B C 2 3 5 7 4 Safe Sequence: < P1, P3 > 12 January 2019 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Example Process P0 P1 P2 P3 P4 Need A B C 7 4 3 0 2 0 6 0 0 0 1 1 4 3 1 Allocation A B C 0 1 0 3 0 2 2 1 1 0 0 2 Work A B C 2 3 5 7 4 Safe Sequence: < P1, P3, P4 > 12 January 2019 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Example Process P0 P1 P2 P3 P4 Need A B C 7 4 3 0 2 0 6 0 0 0 1 1 4 3 1 Allocation A B C 0 1 0 3 0 2 2 1 1 0 0 2 Work A B C 2 3 5 7 4 Safe Sequence: <P1, P3, P4, P0> 12 January 2019 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Example Executing safety algorithm shows that sequence <P1,P3,P4,P0,P2> satisfies safety requirement. Yes, P1’s request may be granted immediately. 12 January 2019 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan More Examples Can request for (0,2,0) by P0 be granted? Is Request0  Need0? (0,2,0)  (7,4,3)  true Is Request1  Available? (0,2,0)  (3,3,2)  true 12 January 2019 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Example Process P0 P1 P2 P3 P4 Need A B C 7 4 3 1 2 2 6 0 0 0 1 1 4 3 1 Allocation A B C 0 1 0 2 0 0 3 0 2 2 1 1 0 0 2 Available A B C 3 2 12 January 2019 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Example Process P0 P1 P2 P3 P4 Need A B C 7 2 3 1 2 2 6 0 0 0 1 1 4 3 1 Allocation A B C 0 3 0 2 0 0 3 0 2 2 1 1 0 0 2 Work A B C 3 1 2 Safe Sequence: <> 12 January 2019 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Example Process P0 P1 P2 P3 P4 Need A B C 7 2 3 1 2 2 6 0 0 0 1 1 4 3 1 Allocation A B C 0 3 0 2 0 0 3 0 2 2 1 1 0 0 2 Work A B C 3 1 2 5 Safe Sequence: < P3 > 12 January 2019 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Example Process P0 P1 P2 P3 P4 Need A B C 7 2 3 1 2 2 6 0 0 0 1 1 4 3 1 Allocation A B C 0 3 0 2 0 0 3 0 2 2 1 1 0 0 2 Work A B C 3 1 2 5 7 Safe Sequence: < P3,P1 > 12 January 2019 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Example Process P0 P1 P2 P3 P4 Need A B C 7 2 3 1 2 2 6 0 0 0 1 1 4 3 1 Allocation A B C 0 3 0 2 0 0 3 0 2 2 1 1 0 0 2 Work A B C 3 1 2 5 7 10 Safe Sequence: < P3,P1,P2 > 12 January 2019 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Example Process P0 P1 P2 P3 P4 Need A B C 7 2 3 1 2 2 6 0 0 0 1 1 4 3 1 Allocation A B C 0 3 0 2 0 0 3 0 2 2 1 1 0 0 2 Work A B C 3 1 2 5 7 10 Safe Sequence: <P3,P1,P2,P0,P4> 12 January 2019 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Example Executing safety algorithm shows that sequence <P3,P1,P2,P0,P4> satisfies safety requirement. Yes, P0’s request may be granted immediately. 12 January 2019 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan More Examples Can request for (3,3,0) by P4 be granted? Do it yourself! 12 January 2019 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Recap of Lecture Deadlock avoidance Banker’s algorithm Safety algorithm Safe state Safe sequence 12 January 2019 © Copyright Virtual University of Pakistan

Lecture 28 Syed Mansoor Sarwar Operating Systems Lecture 28 Syed Mansoor Sarwar