Chapter 4 : Deadlock By : Jigar M. Pandya.

Slides:



Advertisements
Similar presentations
Chapter 7: Deadlocks.
Advertisements

Chapter 5 Deadlocks. Contents What is deadlock? What is deadlock? Characterization Characterization Resource allocation graph Resource allocation graph.
OPERATING SYSTEMS DEADLOCKS
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.
Chapter 7 Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts - 7 th Edition, Feb 14, 2005 Chapter 7: Deadlocks 7.1 System Model.
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.
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.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Bridge Crossing Example Traffic only in one direction. Each section.
What we will cover…  The Deadlock Problem  System Model  Deadlock Characterization  Methods for Handling Deadlocks  Deadlock Prevention  Deadlock.
7: Deadlocks1 DEADLOCKS EXAMPLES: "It takes money to make money". You can't get a job without experience; you can't get experience without a job. BACKGROUND:
Deadlock Characterization
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.
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.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 28 Handling Deadlock.
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.
Operating Systems (CS 340 D) Dr. Abeer Mahmoud Princess Nora University Faculty of Computer & Information Systems Computer science Department.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts - 7 th Edition, Feb 14, 2005 Chapter 7: Deadlocks The Deadlock.
Chapter 7 Deadlocks Chapter 7: Deadlocks 7.1 System Model 7.2 Deadlock Characterization 7.3 Methods for Handling Deadlocks 7.4 Deadlock Prevention 7.5.
1 OPERATING SYSTEMS DEADLOCKS created by:-gaurav shrivastava contact:- om.
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.
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.
1 CS.217 Operating System By Ajarn..Sutapart Sappajak,METC,MSIT Chapter 6 Deadlocks Slide 1 Chapter 6 Deadlocks.
Deadlock. Chapter 7: Deadlocks 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. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 7: Deadlocks The Deadlock Problem System Model Deadlock.
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);
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.
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.
G.Anuradha Ref:- Galvin
Chapter 7: Deadlocks Source & Copyright: Operating System Concepts, Silberschatz, Galvin and Gagne.
Operating Systems (CS 340 D)
Chapter 7: Deadlocks.
Operating System: DEADLOCKS
OPERATING SYSTEMS DEADLOCKS
Chapter 7 Deadlocks.
Process Deadlocks.
Chapter 7: Deadlocks.
Deadlock B.Ramamurthy CSE421 1/11/2019 B.Ramamurthy.
G.Anuradha Ref:- Galvin
Chapter 7: Deadlocks.
Deadlock B.Ramamurthy CSE421 2/23/2019 B.Ramamurthy.
Deadlocks Session - 13.
Chapter 7: Deadlocks.
Deadlock B.Ramamurthy CSE421 4/23/2019 B.Ramamurthy.
Deadlock B.Ramamurthy CSE421 5/1/2019 B.Ramamurthy.
OPERATING SYSTEMS DEADLOCKS.
DEADLOCKS.
CSCI 315 Operating Systems Design
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:

Chapter 4 : Deadlock By : Jigar M. Pandya

Deadlock A Process Must request a resource before using it. And Process release the resource after using it. Sequence of events required to use a resource: Request the resource. Use the resource. Release the resource. By : Jigar M. Pandya

Deadlock Examaple : By : Jigar M. Pandya

Deadlock A deadlock consists of a set of blocked processes, each holding a resource and waiting to acquire a resource held by another process in the set. By : Jigar M. Pandya

Deadlock Characterization Deadlock can arise if four conditions hold simultaneously. Mutual exclusion: only one process at a time can use a resource By : Jigar M. Pandya

Deadlock Characterization Deadlock can arise if four conditions hold simultaneously. 2. Hold and wait: a process holding at least one resource is waiting to acquire additional resources held by other processes By : Jigar M. Pandya

Deadlock Characterization Deadlock can arise if four conditions hold simultaneously. 3. No preemption: a resource can be released only voluntarily by the process holding it after that process has completed its task By : Jigar M. Pandya

Deadlock Characterization Deadlock can arise if four conditions hold simultaneously. 4. Circular wait: there exists a set {P0, P1, …, P0} of waiting processes such that P0 is waiting for a resource that is held by P1, P1 is waiting for a resource that is held by P2, …, Pn–1 is waiting for a resource that is held by Pn, and Pn is waiting for a resource that is held by P0 By : Jigar M. Pandya

Resource-Allocation Graph A set of vertices V and a set of edges E. V is partitioned into two types: P = {P1, P2, …, Pn}, the set consisting of all the processes in the system R = {R1, R2, …, Rm}, the set consisting of all resource types in the system request edge – directed edge P1 -> Rj assignment edge – directed edge Rj -> Pi By : Jigar M. Pandya

Resource-Allocation Graph ‏ Process Resource Type with 4 instances Pi requests instance of Rj Pi is holding an instance of Rj Pi Pi By : Jigar M. Pandya

Resource Allocation Graph With A Deadlock Before P3 requested an instance of R2 After P3 requested an instance of R2 A Cycle In the Graph May cause Deadlock By : Jigar M. Pandya

Graph With A Cycle But No Deadlock Process P4 may release its instance of resource type R2. That resource can then be allocated to P3, thereby breaking the cycle. By : Jigar M. Pandya

Deadlock By : Jigar M. Pandya

Methods for Handling Deadlocks Prevention Ensure that the system will never enter a deadlock state Avoidance Ensure that the system will never enter an unsafe state Detection Allow the system to enter a deadlock state and then recover Do Nothing Ignore the problem and let the user or system administrator respond to the problem; used by most operating systems, including Windows and UNIX By : Jigar M. Pandya

Deadlock Prevention By : Jigar M. Pandya

Do not allow one of the four conditions to occur. Deadlock Prevention To prevent deadlock, we can restrain the ways that a request can be made  Do not allow one of the four conditions to occur. Mutual Exclusion : if no resource were ever assigned to a single process exclusively ,we would never have deadlock. Shared entities (read only files) don't need mutual exclusion (and aren’t susceptible to deadlock.) Prevention not possible, since some devices are naturally non-sharable By : Jigar M. Pandya

Do not allow one of the four conditions to occur. Deadlock Prevention To prevent deadlock, we can restrain the ways that a request can be made  Do not allow one of the four conditions to occur. Hold And Wait : we must guarantee that whenever a process requests a resource, it does not hold any other resources Require a process to request and be allocated all its resources before it begins execution allow a process to request resources only when the process has none Result: Low resource utilization; starvation possible By : Jigar M. Pandya

Do not allow one of the four conditions to occur. Deadlock Prevention To prevent deadlock, we can restrain the ways that a request can be made  Do not allow one of the four conditions to occur. No Preemption : If a process that is holding some resources requests another resource that cannot be immediately allocated to it, then all resources currently being held are released Pi  Rj  Pj  Rk A process will be restarted only when it can regain its old resources, as well as the new ones that it is requesting. Allow preemption - if a needed resource is held by another process, which is also waiting on some resource, steal it. Otherwise wait. By : Jigar M. Pandya

Do not allow one of the four conditions to occur. Deadlock Prevention To prevent deadlock, we can restrain the ways that a request can be made  Do not allow one of the four conditions to occur. Circular Wait : impose a total ordering of all resource types, and require that each process requests resources in an increasing order of enumeration. F : R  N F(ri) < F(rj) P1 r1  P2  r2  P3……. Pn-1  rn  Pn For example: F(tape drive) = 1 F(disk drive) = 5 F(printer) = 12 By : Jigar M. Pandya

Deadlock Prevention EACH of these prevention techniques may cause a decrease in utilization and/or resources. For this reason, prevention isn't necessarily the best technique. Prevention is generally the easiest to implement. By : Jigar M. Pandya

Deadlock Avoidance Process must declare all the required resource before starting the execution. P1 Requires A,B. P2 Requires B,A. 1) P1  A 2) P2  B P1 Wait Wait Wait 3) P1  B A B Process P1 Complete Release Resource 4) P2  B P2 5) P2  A Process P2 Complete Release Resourece By : Jigar M. Pandya

Deadlock Avoidance Simplest and most useful model requires that each process declare the maximum number of resources of each type that it may need The deadlock-avoidance algorithm dynamically examines the resource-allocation state to ensure that there can never be a circular-wait condition A resource-allocation state is defined by the number of available and allocated resources, and the maximum demands of the processes By : Jigar M. Pandya

Deadlock Avoidance Possible states are:   Deadlock No forward progress can be made. Unsafe state A state that may allow deadlock. Safe state A state is safe if a sequence of processes exist such that there are enough resources for the first to finish, and as each finishes and releases its resources there are enough for the next to finish. The rule is simple: If a request allocation would cause an unsafe state, do not honor that request. By : Jigar M. Pandya

Only with luck will processes avoid deadlock. Deadlock Avoidance NOTE: All deadlocks are unsafe, but all unsafes are NOT deadlocks. SAFE UNSAFE DEADLOCK Only with luck will processes avoid deadlock. O.S. can avoid deadlock. By : Jigar M. Pandya

Deadlock Avoidance EXAMPLE: There exists a total of 12 resources. Each resource is used exclusively by a process. The current state looks like this: In this example, < p1, p0, p2 > is a workable sequence. Free = 2 Suppose p2 requests and is given one more resource. What happens then? Free= 1 Process Max Needs Allocated Current Needs P0 10 5 P1 4 2 P2 9 3 7 Process Max Needs Allocated Current Needs P0 10 5 P1 4 2 P2 9 7 By : Jigar M. Pandya

Avoidance algorithms For a single instance of a resource type, use a resource-allocation graph For multiple instances of a resource type, use the banker’s algorithm By : Jigar M. Pandya

Resource-Allocation Graph with Claim Edges Assignment edge Request edge Claim edge Claim edge By : Jigar M. Pandya

Unsafe State In Resource-Allocation Graph Assignment edge Request edge Assignment edge Claim edge By : Jigar M. Pandya

Resource-Allocation Graph Algorithm Suppose that process Pi requests a resource Rj The request can be granted only if converting the request edge to an assignment edge does not result in the formation of a cycle in the resource allocation graph By : Jigar M. Pandya

Data Structures for the Banker’s Algorithm Let n = number of processes, and m = number of resources types. Available: Vector of length m. If available [j] = k, there are k instances of resource type Rj available. 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. Need: n x m matrix. If Need[i,j] = k, then Pi may need k more instances of Rj to complete its task. By : Jigar M. Pandya

Banker’s Algorithm Safety Algorithm A method used to determine if a particular state is safe. It's safe if there exists a sequence of processes such that for all the processes, there’s a way to avoid deadlock: The algorithm uses these variables:   Need[I] – the remaining resource needs of each process. Work - Temporary variable – how many of the resource are currently available. Finish[I] – flag for each process showing we’ve analyzed that process or not. need <= available + allocated[0] + .. + allocated[I-1]  Sign of success Let work and finish be vectors of length m and n respectively. By : Jigar M. Pandya

Banker’s Algorithm Safety Algorithm 1. Initialize work = available Initialize finish[i] = false, for i = 1,2,3,..n   2. Find an i such that: finish[i] == false and need[i] <= work If no such i exists, go to step 4. 3. work = work + allocation[i] finish[i] = true goto step 2 4. if finish[i] == true for all i, then the system is in a safe state. By : Jigar M. Pandya

Banker’s Algorithm Context Of Matrix need Is Calculated As Need = Max - Allocation By : Jigar M. Pandya

Banker’s Algorithm By : Jigar M. Pandya

Banker’s Algorithm By : Jigar M. Pandya

Banker’s Algorithm By : Jigar M. Pandya