Deadlock Permanent blocking of a set of process that compete for system resources or communicate with each other. Conditions that characterizes deadlock.

Slides:



Advertisements
Similar presentations
Chapter 7: Deadlocks.
Advertisements

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.
1 School of Computing Science Simon Fraser University CMPT 300: Operating Systems I Ch 7: Deadlock Dr. Mohamed Hefeeda.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 7: Deadlocks.
1 School of Computing Science Simon Fraser University CMPT 300: Operating Systems I Ch 7: Deadlock Dr. Mohamed Hefeeda.
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.
System Model Deadlock Characterization Methods for Handling Deadlocks Deadlock Prevention, Avoidance, and Detection Recovering from Deadlock Combined Approach.
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.
Chapter 7: Deadlocks. The Deadlock Problem A set of blocked processes each holding a resource and waiting to acquire a resource held by another process.
CHAPTER 8: DEADLOCKS System Model Deadlock Characterization
CS6502 Operating Systems - Dr. J. Garrido Deadlock – Part 2 (Lecture 7a) CS5002 Operating Systems Dr. Jose M. Garrido.
Chapter 8: Deadlocks Deadlock Characterization Methods for Handling Deadlocks Deadlock Prevention Deadlock Avoidance Deadlock Detection Recovery from Deadlock.
 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 8 Deadlocks. Objective System Model Deadlock Characterization Methods for Handling Deadlocks Deadlock Prevention Deadlock Avoidance Deadlock Detection.
1 CS.217 Operating System By Ajarn..Sutapart Sappajak,METC,MSIT Chapter 6 Deadlocks Slide 1 Chapter 6 Deadlocks.
Deadlocks - System Model - Deadlock characterization - Methods for handling deadlocks - Deadlock prevention,avoidance - Deadlock detection and recovery.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 7: Deadlocks The Deadlock Problem System Model Deadlock.
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.
Module 6: Deadlocks Reading: Chapter 7 Objective:
Thursday, February 23, 2012 Chapter 6 homework questions?
Chapter 7: Deadlocks.
OPERATING SYSTEM CONCEPTS AND PRACTISE
Process Management Deadlocks.
Chapter 7: Deadlocks.
Operating System Concepts
Concurrency: Deadlock and Starvation
Deadlock Management.
G.Anuradha Ref:- Galvin
Operating Systems (CS 340 D)
Chapter 7: Deadlocks.
Operating System: DEADLOCKS
OPERATING SYSTEMS DEADLOCKS
Chapter 7 Deadlocks.
CSCI 511 Operating Systems Chapter 7 Deadlock
Process Deadlocks.
Chapter 7: Deadlocks System Model Deadlock Characterization
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.
CSc 552 Advanced Unix Process deadlock deadlock prevention
Deadlocks Session - 14.
Deadlock B.Ramamurthy CSE421 2/23/2019 B.Ramamurthy.
DEADLOCK.
Chapter 7: Deadlocks.
Deadlock Hank Levy 1.
Deadlock B.Ramamurthy CSE421 4/23/2019 B.Ramamurthy.
OPERATING SYSTEMS DEADLOCKS.
Deadlock B.Ramamurthy CSE421 5/1/2019 B.Ramamurthy.
OPERATING SYSTEMS DEADLOCKS.
DEADLOCKS.
CSCI 315 Operating Systems Design
Chapter 7: Deadlocks.
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:

Deadlock Permanent blocking of a set of process that compete for system resources or communicate with each other. Conditions that characterizes deadlock Mutual exclusion Hold and wait No pre-emption Circular wait

Resource allocation graph Mathematically G=(V,E) Where V={P,R} , P=set of Processes and R=set of Recources And E={set of Claim Edge, Set of Allocation Edge} Claim or request edge, from process to resource Allocation edge, from resource to process P1 P2 P3 P5 P4 R2 R5 R1 R4 R3

Different methods of deadlock handling Prevention ensure that one of the condition for characterizing deadlock does not arise. Avoidance avoid the situations that may lead us to deadlock. Detection and recovery if the system faces deadlock, detect it and then take the measure to recover from it.

Deadlock Prevention Ensuring that Hold and Wait never occur Ensure that when a process makes a request for a new resource, at that time it does not hold any other resource. Grab all the required resource at the very beginning. Drawbacks Process may face starvation Resource utilization is very poor Alternate approach, release the currently holding resources when a new request is made.

Deadlock Prevention Allowing preemption If a process makes a request for a new resource, and the request can’t be granted then OS will preempt all the resource from this process and in the list of resource for which the process is waiting, add these resources. Later on the process has to grab these preempted resource as well as that resource for which it gave the request. P0 A C P1 B Request can’t be granted P0 waits for resource B, and resource A and C are Preempted. Finally P0 waits for resource A,B and C

Deadlock Prevention Allowing preemption Alternate approach : If the request can’t be granted, check whether the resource is currently held by any active process or not. If yes then the process which have made the request will go to wait state. If no , held by a waiting process, then preempt the resource from the waiting process. In this way all the resource from a waiting process may be taken away. When such a waiting process will start again it has to grab all the resource that it has loosed while waiting. This protocol is applicable for those resources whose state can be easily saved and restored, like CPU registers Memory Spaces etc. It can’t be applied to to resources like Printer tape drive etc. P1(ready) B C P0 A P3(waiting) B C P2 executes by Preempting resource B from P3. P2 A P0 goes to wait state

Deadlock Prevention Not allowing to occur the Circular wait Circular wait can be prevented by defining a linear ordering of resources. If a process is holding a resource R, then it can subsequently request only those resources of types following R in the ordering. i.e. Resource are allocated in increasing order. Resource type are assigned a unique number, F(Ri). If a process request for a new resource Ri then it must first release all resources Rj, if it is holding, such that F(Rj)F(Ri). It will guarantee that there will be no circular wait. Proof: Let there is a circular wait P0 P1 … Pn-1 Pn P0 If it happens then F(R0)< F(R1)< …..< F(Rn-1)< F(Rn)< F(R0) must be satisfied. But it contradicts that F(R0)< F(R0)

Deadlock Avoidance In the situation of single instance of every resource type— When a process makes a request for a resource, request can be granted if no cycle is formed in the resource allocation graph after converting that claim edge to an allocation edge. P1 P2 R1 R2 P1 P2 R1 R2 P1 P2 R1 R2

Deadlock Avoidance Banker’s algorithm If there are multiple instances of different resource types, a cycle in the resource allocation graph is not sufficient to declare deadlock. Different data structures used in Banker’s algorithm Available : 1-array, Available[i]=k means k instances of i-th resource type is currently available. Max : 2- dimensional array, Max[i][j]=k means process Pi can request for at most k instances of resource Rj. Allocation : 2- dimensional array, Allocation [i][j]=k means process Pi is currently holding k instances of resource Rj. Need : 2- dimensional array, Need[i][j]=k means process Pi needs k more instances of resource Rj. Need[i][j]=max[i][j] – Allocation [i][j]

Deadlock Avoidance Banker’s algorithm (Contd.) Works in two phase Resource request algorithm Changes in the various data structure is done here Safety algorithm Checks whether the state is safe or not. A state is called unsafe if it leads to a deadlock state. Otherwise the state is safe.

Deadlock Avoidance Resource request algorithm (Contd.) Requesti is the request vector of process Pi; Requesti[j]=k means at this moment Pi nwants k instances of resource Rj. If Requesti  Needi go to step 2. Else declare error. If Requesti  Available go to step 3. Else Pi has to wait. Do the following changes Available= Available - Requesti Allocationi = Allocationi + Requesti Needi = Needi - Requesti

Deadlock Avoidance (Contd.) safety algorithm Temporary data structure used Work and Finish, arrays of length #resources and #processes respectively. Initialize, work=Available and i Finish[i]=false Find an i such that (( Finish[i]=false) && (Needi  Work)) If no such i exists then go to step 4 Work=work+allocationi Finish[i]=true Go to step 2 If i Finish[i]=true then the system is in a safe state. Else the system is in a unsafe state and undo the changes in the data structures done by the first phase.

Example Process Allocation Max Available A B C P0 0 1 0 7 5 3 3 3 2 P1 2 0 0 3 2 2 P2 3 0 2 9 0 2 P3 2 1 1 2 2 2 P4 0 0 2 4 3 3 Need A B C 7 4 3 1 2 2 6 0 0 0 1 1 4 3 1 Finish F P0 7 5 5 + 6 0 0 T P1 5 3 2 + 2 1 1 T P2 13 5 5 T P3 7 4 3 + 0 0 2 T P4 7 4 5 + 0 1 0 T Work = 3 3 2 + 2 0 0

Example If the current state of the system is as given below, can the request by P0 for (0,0,2) be granted ? Process Allocation Max Available A B C P0 0 1 0 7 5 3 3 3 2 P1 2 0 0 3 2 2 P2 3 0 2 9 0 2 P3 2 1 1 2 2 2 P4 0 0 2 4 3 3 Need A B C 7 4 3 1 2 2 6 0 0 0 1 1 4 3 1 Resource Request Algorithm Change Available 0 1 2 Change Need0 Change Allocation0 3 3 0 7 4 1 The allocation of the resource to process P0 leads us to this new state where the available resource can not satisfy request for maximum claim by any process. That means it is an unsafe state. So the request will not be granted.

Drawback of banker’s algorithm It has to maintain the data structures. Which wastes a lot of memory space. To collect the information for Max matrix is not a simple job, it will waste a lot of CPU time. Drawback of all deadlock Avoidance Avoidance algorithm has to be executed every time a process makes a request for a resource. But every resource allocation will not lead us to deadlock. i.e. we have to execute the algorithm if there is no chance of deadlock. In other words it will waste a lot of CPU time.

Detection and Recovery Resources have single instances Cycle in the wait-for graph will declare that there is a deadlock Wait-for graph can be obtained from resource allocation graph. If there are two edges Pi  Rb and Rb  Pj in the resource allocation graph, then there will be an edge Pi  Pj in the wait-for graph. P1 P2 P3 P5 P4 R2 R5 R1 R4 R3 P1 P2 P3 P5 P4

Detection and Recovery Resources have multiple instances Reduction of Resource allocation graph Graph is reduced by Pi if a) Pi has no request edge b) Pi is not blocked c) There is assignment edge directed to Pi. P0 P1 P2 R0   R2 R1  P0 P1 P2 R0   R2 R1  P0 P1 P2 R0   R2 R1  P0 P1 P2 R0   R2 R1  There is no deadlock if the graph can be reduced to zero edges

Detection and Recovery Resources have multiple instances   R2 R1  This graph can’t be reduced, so there is a deadlock

Detection and Recovery Variation of banker’s algorithm (multiple instances ) Uses three data structures Available and Allocation And Request 2-dimensional array Initialize, work=Available and i Finish[i]=false Find an i such that (( Finish[i]=false) && (Requesti  Work)) If no such i exists then go to step 4 Work=work+allocationi Finish[i]=true Go to step 2 If i Finish[i]=true then the system is in a safe state. Else the system is in a unsafe state and undo the changes in the data structures done by the first phase.

Recovery Abort all deadlocked processes. Back up each deadlocked process to some previously defined checkpoint and restart, deadlock may re-occur here. Successively abort deadlocked processes until deadlock no longer exits. Select the victim depending on some minimum cost. Successively preempt resources until deadlock no longer exits. Select the victim depending on some minimum cost. Least amount of CPU time comsumed Least no of output produced Most estimated time remaining Least total resource allocated so far Lowest priority