Operating Systems, Summer Semester 2011

Slides:



Advertisements
Similar presentations
Chapter 7: Deadlocks.
Advertisements

Deadlock 2.
Lecture 7: Deadlock     Necessary Conditions for Deadlock     Deadlock Prevention - Havender's Linear Ordering Deadlock Avoidance Deadlock Detection &
MODERN OPERATING SYSTEMS Third Edition ANDREW S
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.
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.
Ceng Operating Systems Chapter 2.4 : Deadlocks Process concept  Process scheduling  Interprocess communication  Deadlocks Threads.
Operating Systems COMP 4850/CISG 5550 Deadlock Avoidance Dr. James Money.
MODERN OPERATING SYSTEMS Third Edition ANDREW S. TANENBAUM Chapter 6 Deadlocks Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All.
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.
Deadlock Detection with One Resource of Each Type (1)
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.
1 MODERN OPERATING SYSTEMS Third Edition ANDREW S. TANENBAUM Chapter 6 Deadlocks Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc.
MODERN OPERATING SYSTEMS Third Edition ANDREW S. TANENBAUM Chapter 6 Deadlocks Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All.
Chapter 8: Deadlocks Deadlock Characterization Methods for Handling Deadlocks Deadlock Prevention Deadlock Avoidance Deadlock Detection Recovery from Deadlock.
Operating Systems, 152 Practical Session 8 Deadlocks 1.
CS333 Intro to Operating Systems Jonathan Walpole.
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.
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
CSSE 332 Operating Systems Rose-Hulman Institute of Technology
Chapter 7: Deadlocks.
Operating Systems, Winter Semester 2011
MODERN OPERATING SYSTEMS Third Edition ANDREW S
Chapter 6 : Deadlocks What is a Deadlock?
Operating Systems (CS 340 D)
Chapter 7: Deadlocks.
Operating System: DEADLOCKS
OPERATING SYSTEMS DEADLOCKS
Lecture 18: Deadlock: Conditions, Detection and Avoidance (cont.)
Chapter 7 Deadlocks.
Process Deadlocks.
Practical Session 12 Deadlocks
Deadlock B.Ramamurthy CSE421 1/11/2019 B.Ramamurthy.
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.
MODERN OPERATING SYSTEMS Third Edition ANDREW S
Deadlocks Peng Lu In a multiprogramming environment, several processes may compete for a finite number of resources. A process requests resources; if the.
Chapter 8: Deadlocks.
Deadlock B.Ramamurthy CSE421 2/23/2019 B.Ramamurthy.
Deadlocks Session - 13.
DEADLOCK.
Lecture 27 Syed Mansoor Sarwar
Chapter 7: Deadlocks.
Deadlock B.Ramamurthy CSE421 4/23/2019 B.Ramamurthy.
IT3002 Computer Architecture
Deadlock B.Ramamurthy CSE421 5/1/2019 B.Ramamurthy.
OPERATING SYSTEMS DEADLOCKS.
DEADLOCKS.
CSE 380 Lecture Note 12 Insup Lee
CSCI 315 Operating Systems Design
Chapter 7: Deadlocks.
Deadlock B.Ramamurthy CSE421 8/28/2019 B.Ramamurthy.
Deadlock B.Ramamurthy CSE421 9/3/2019 B.Ramamurthy.
MODERN OPERATING SYSTEMS Third Edition ANDREW S
Presentation transcript:

Operating Systems, 371-1-1631 Summer Semester 2011 Practical Session 8 Deadlocks

Deadlocks The ultimate form of starvation. A set of processes is deadlocked if each process in the set is waiting for an event that only another process in the set can cause.

Conditions for Deadlock Mutual exclusion - resource used by only one process Hold and wait - process can request resource while holding another resource No preemption - only process can release resource Circular wait - 2 or more processes waiting for resources held by other (waiting) processes

Solving the Deadlock Problem The Ostrich ‘Algorithm’ – Ignore the problem Deadlock Detection & Recovery – Detect a deadlock by finding a cyclic graph of processes and resources and recover. Deadlock Avoidance – Detect safe and unsafe states; Bankers algorithm. Deadlock Prevention – Ensure that at least one of the four conditions for a deadlock is never satisfied.

Question 1 Assume resources are ordered as: R1, R2,...Rn Prove formally (by negation) that if processes always request resources by order (i.e. if a process requests Rk after Rj then k>j) then a deadlock will not occur. For simplicity assume resources are unique. That is, there is a single unit of each resource.

Question 1 – a simple example There are 2 processes P1 ,P2 and resource R1 ,R2. P1 has R1 and P2 has R2. P1 requests R2 and is now waiting for P2 to release it. For a deadlock to occur P2 needs to request R1. However, this is in contrast to the assumption that resources can only be requested in ascending order. Condition 4 (Circular wait) is prevented.

Question 1 – a more formal proof Suppose that our system is prone to deadlocks. Let us number our processes P1,...,Pn. Consider the last condition required for a deadlock (Circular wait). Denote with Pi - Rk->Pj the situation where Pi requests a resource Rk held by Pj. For a deadlock to occur, a subset Pi1,...,Pim of {P1,...,Pn} which satisfies the following condition must exist: Pi1 - (Rj,1)->Pi2 - (Rj,2)->...- (Rj,m-1)->Pim - (Rj,m)->Pi1 (*)

Question 1 – a more formal proof For each process Pi,s , s≠1 , Pi,s holds resource Rj,s-1 and requests resource Rj,s. This means that j,s-1<j,s for any s (since the resources are numbered, and are requested in an ascending order). We receive the following inequality: j,1<j,2<...<j,m. In a deadlock eq. (*) must hold and from it we conclude that j,m<j,1. We receive the following necessary conditions j,1<j,m and j,1>j,m for a circular wait. Hence a circular wait will not occur, and the system is deadlock- free.

Banker’s Algorithm Safe – a state is said to be safe if It is not deadlocked. There is some scheduling order in which every process can run to completion even if all of them suddenly request their maximum number of resources immediately.

Banker’s Algorithm Resources: Vectors: E - Number of Existing resources of each type. P – Number of resources of each type in Possession by the processes. A – Number of Available resources of each type. Matrices: (rows are processes and columns are resources) C – Current allocation matrix R – Request matrix

Banker’s Algorithm Look for a row in matrix R whose unmet resource needs are all smaller than or equal to A. If no such row exists, the system may eventually deadlock. Assume the process of the row chosen finishes (which is possible). Mark that process as terminated and add all its resources to the A vector Repeat steps 1 and 2 until either all processes are marked terminated, which means safe, or until a deadlock occurs, which means unsafe.

Question 2 Consider the following snapshot of a system with five processes (p1, ... p5) and four resources (r1, ... r4). r1 r2 r3 r4 2 1 currently Available resources current allocation max demand still needs Process r1 r2 r3 r4 p1 1 2 p2 7 5 p3 3 4 6 p4 p5

Question 2 a. Compute what each process still might request and fill in the “still needs” columns. b. Is this system currently deadlocked, or will any process become deadlocked? Use the baker’s algorithm to support your answer

Question 2 a) current allocation max demand still needs r1 r2 r3 r4 p1 Process r1 r2 r3 r4 p1 1 2 p2 7 5 p3 3 4 6 p4 p5 a)

Question 2 a) Not deadlocked and will not become deadlocked. current allocation max demand still needs Process r1 r2 r3 r4 p1 1 2 p2 7 5 p3 3 4 6 p4 p5 a) Not deadlocked and will not become deadlocked. Using the Banker’s algorithm, we determine the process execution order: p1, p4, p5, p2, p3. b) r1 r2 r3 r4 2 1 currently available resources

Question 2 c. If a request from p3 arrives for (0, 1, 0, 0), can that request be safely granted immediately? In what state (deadlocked, safe, unsafe) would immediately granting the whole request leave the system? Which processes, if any, are or may become deadlocked if this whole request is granted immediately?

Question 2 current allocation max demand still needs r1 r2 r3 r4 p1 1 Process r1 r2 r3 r4 p1 1 2 p2 7 5 p3 3 4 6 p4 p5 r1 r2 r3 r4 2 currently available resources

Question 2 c) Change available to (2, 0, 0, 0) and p3’s row of “still needs” to (6, 5, 2, 2). Now p1, p4, and p5 can finish. Available will now be (4, 6, 9, 8) meaning that neither p2 nor p3’s “still needs” can be satisfied. So, it is not safe to grant p3’s request. Correct answer NO. Processes p2 and p3 may deadlock.

Question 3 (7.6 from Silberschats) If deadlocks are controlled (avoided) by applying the banker‘s algorithm, which of the following changes can be made safely and under what circumstances: Increase Available (add new resources) Decrease Available (remove resources) Increase Max for one process Increase the number of processes

Question 3 Increasing the number of resources available can't create a deadlock since it can only decrease the number of processes that have to wait for resources. Decreasing the number of resources can cause a deadlock.

Question 3 Error condition could be created for two possible reasons: From Banker's algorithm point of view, process exceeds its maximum claim; Condition that was thought to be safe ceases to be safe If the number of processes is increased, the state remains safe , since we can first run the “old”  processes, until they terminate, and release all their resources. Now , when all the system’s resources are free, we can choose a “new” process and give it all its demands. It will finish and again all the system’s resources will be free. Again, we choose a new process and give it all its demands , etc.