Ceng 334 - Operating Systems 2.4-1 Chapter 2.4 : Deadlocks Process concept  Process scheduling  Interprocess communication  Deadlocks Threads.

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.
Deadlock and Starvation
1 Deadlock Solutions: Avoidance, Detection, and Recovery CS 241 March 30, 2012 University of Illinois.
Concurrency: Deadlock and Starvation Chapter 6. Deadlock Permanent blocking of a set of processes that either compete for system resources or communicate.
Lecture 7: Deadlock     Necessary Conditions for Deadlock     Deadlock Prevention - Havender's Linear Ordering Deadlock Avoidance Deadlock Detection &
6. Deadlocks 6.1 Deadlocks with Reusable and Consumable Resources
MODERN OPERATING SYSTEMS Third Edition ANDREW S
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.
Chapter 3 Deadlocks TOPICS Resource Deadlocks The ostrich algorithm
1 Deadlocks Chapter Resource 3.2. Introduction to deadlocks 3.3. The ostrich algorithm 3.4. Deadlock detection and recovery 3.5. Deadlock avoidance.
Chapter 3 Deadlocks - Αδιέξοδα 3.1. Resource
Avishai Wool lecture Introduction to Systems Programming Lecture 5 Deadlocks.
Deadlock Chapter 3 R1 R2 P2P1 Allocated Requested.
CSC 322 Operating Systems Concepts Lecture - 29: by
Chapter 7: Deadlocks. 7.2 Chapter Objectives To develop a description of deadlocks, which prevent sets of concurrent processes from completing their tasks.
Deadlock CSCI 444/544 Operating Systems Fall 2008.
CS 450 OPERATING SYSTEMS DEADLOCKS Manju Muralidharan Priya.
Chapter 3 Deadlocks 3.1. Resource 3.2. Introduction to deadlocks
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 7: Deadlocks.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 7: Deadlocks.
Deadlock Chapter 3 Thursday, February 22, Today’s Schedule Assignment #4 from Chapter 3 posted Deadlock - Chapter 3  Skip multiple resources (3.4.2.
1 Deadlocks Chapter Resource 3.2. Introduction to deadlocks 3.3. The ostrich algorithm 3.4. Deadlock detection and recovery 3.5. Deadlock avoidance.
1 Deadlocks Chapter Resource 3.2. Introduction to deadlocks 3.4. Deadlock detection and recovery 3.5. Deadlock avoidance 3.6. Deadlock prevention.
1 Deadlocks 2 Resources Examples of computer resources –printers –tape drives –tables Processes need access to resources in reasonable order Suppose.
1 Deadlocks Chapter Resource 3.2. Introduction to deadlocks 3.3. The ostrich algorithm 3.4. Deadlock detection and recovery 3.5. Deadlock avoidance.
1 Deadlocks Chapter 3. 2 Resources Examples of computer resources –printers –tape drives –tables Processes need access to resources in reasonable order.
Operating Systems 软件学院 高海昌 Operating Systems Gao Haichang, Software School, Xidian University 22 Contents  1. Introduction** 
Operating Systems Part III: Process Management (Deadlocks)
1 Deadlock Definition of deadlock Condition for its occurrence Solutions for avoiding and breaking deadlock –Deadlock Prevention –Deadlock Avoidance –Deadlock.
1 Deadlocks Chapter Resource 3.2. Introduction to deadlocks 3.3. The ostrich algorithm 3.4. Deadlock detection and recovery 3.5. Deadlock avoidance.
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.
Operating Systems (OS)
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 7: Deadlocks.
MODERN OPERATING SYSTEMS Third Edition ANDREW S. TANENBAUM Chapter 6 Deadlocks Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All.
Operating Systems (CS 340 D) Dr. Abeer Mahmoud Princess Nora University Faculty of Computer & Information Systems Computer science Department.
CS 346 – Chapter 7 Deadlock –Properties –Analysis: directed graph Handle –Prevent –Avoid Safe states and the Banker’s algorithm –Detect –Recover.
Deadlocks System Model RAG Deadlock Characterization
CS333 Intro to Operating Systems Jonathan Walpole.
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.
Chapter 8 Deadlocks. Objective System Model Deadlock Characterization Methods for Handling Deadlocks Deadlock Prevention Deadlock Avoidance Deadlock Detection.
7.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 7: Deadlocks The Deadlock Problem System Model Deadlock Characterization.
Copyright ©: Nahrstedt, Angrave, Abdelzaher1 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);
Sistem Operasi IKH311 Deadlock. 2 Resources Examples of computer resources printers tape drives tables Processes need access to resources in reasonable.
Deadlocks Lots of resources can only be used by one process at a time. Exclusive access is needed. Suppose process A needs R1 + R2 and B needs R1 + R2.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 7: Deadlocks.
Chapter 7: Deadlocks.
OPERATING SYSTEM CONCEPTS AND PRACTISE
Process Management Deadlocks.
Operating Systems, Summer Semester 2011
Operating Systems, Winter Semester 2011
Deadlock Management.
ITEC 202 Operating Systems
Chapter 7 – Deadlock and Indefinite Postponement
Chapter 6 : Deadlocks What is a Deadlock?
Chapter 7 Deadlocks.
Deadlocks Definition A set of processes is in a Deadlock state when every process in the set is waiting for an event that can only be caused by another.
Chapter 7: Deadlocks.
DPNM Lab. Dept. of CSE, POSTECH
The relation between the process and
Chapter 3 Deadlocks 3.1. Resource 3.2. Introduction to deadlocks
Chapter 3 Deadlocks 3.1. Resource 3.2. Introduction to deadlocks
Introduction to Deadlocks
Chapter 3 Deadlocks 3.1. Resource 3.2. Introduction to deadlocks
Chapter 7: Deadlocks.
Presentation transcript:

Ceng Operating Systems Chapter 2.4 : Deadlocks Process concept  Process scheduling  Interprocess communication  Deadlocks Threads

Ceng Operating Systems What is Deadlock? Process Deadlock –A process is deadlocked when it is waiting on an event which will never happen System Deadlock –A system is deadlocked when one or more processes are deadlocked

Ceng Operating Systems Necessary Conditions for a Deadlock Mutual Exclusion –Shared resources are used in a mutually exclusive manner Hold & Wait –Processes hold onto resources they already have while waiting for the allocation of other resources

Ceng Operating Systems Necessary Conditions for a Deadlock (Cont.) No Preemption –Resources can not be preempted until the process releases them Circular Wait –A circular chain of processes exists in which each process holds resources wanted by the next process in the chain

Ceng Operating Systems No Deadlock Situation If you can prevent at least one of the necessary deadlock conditions then you won’t have a DEADLOCK

Ceng Operating Systems The Ostrich Algorithm Pretend there is no problem Reasonable if –deadlocks occur very rarely –cost of prevention is high UNIX and Windows takes this approach It is a trade off between –convenience –correctness

Ceng Operating Systems Ways of Handling Deadlock Deadlock Prevention Deadlock Detection Deadlock Avoidance Deadlock Recovery

Ceng Operating Systems Deadlock Prevention Remove the possibility of deadlock occurring by denying one of the four necessary conditions: –Mutual Exclusion (Can we share everything?) –Hold & Wait –No preemption –Circular Wait

Ceng Operating Systems Implementation –A process is given its resources on a "ALL or NONE" basis –Either a process gets ALL its required resources and proceeds or it gets NONE of them and waits until it can Denying the “Hold & Wait”

Ceng Operating Systems Advantages –It works –Reasonably easy to code Problems –Resource wastage –Possibility of starvation

Ceng Operating Systems Denying “No preemption” Implementation –When a process is refused a resource request, it MUST release all other resources it holds –Resources can be removed from a process before it is finished with them

Ceng Operating Systems Advantages –It works –Possibly better resource utilisation Problems –The cost of removing a process's resources –The process is likely to lose work it has done. (How often does this occur?) –Possibility of starvation

Ceng Operating Systems Denying “Circular Wait” Implementation –Resources are uniquely numbered –Processes can only request resources in linear ascending order –Thus preventing the circular wait from occurring

Ceng Operating Systems Advantages –It works –Has been implemented in some OSes Problems –Resources must be requested in ascending order of resource number rather than as needed –Resource numbering must be maintained by someone and must reflect every addition to the OS –Difficult to sit down and write just write code

Ceng Operating Systems Deadlock Avoidance Allow the chance of deadlock occur But avoid it happening.. Check whether the next state (change in system) may end up in a deadlock situation

Ceng Operating Systems Banker’s Problem Suppose total bank capital is 1000 MTL Current cash : ( ) = 380 MTL Customer c1 c2 Max. Need Present Loan Claim 390

Ceng Operating Systems Dijkstra's Banker's Algorithm Definitions –Each process has a LOAN, CLAIM, MAXIMUM NEED LOAN: current number of resources held MAXIMUM NEED: total number resources needed to complete CLAIM: = (MAXIMUM - LOAN)

Ceng Operating Systems Assumptions Establish a LOAN ceiling (MAXIMUM NEED) for each process –MAXIMUM NEED < total number of resources available (ie., capital) Total loans for a process must be less than or equal to MAXIMUM NEED Loaned resources must be returned back in finite time

Ceng Operating Systems Algorithm 1.Search for a process with a claim that can satisfied using the current number of remaining resources (ie., tentatively grant the claim) 2. If such a process is found then assume that it will return the loaned resources. 3. Update the number of remaining resources 4.Repeat steps 1-3 for all processes and mark them

Ceng Operating Systems DO NOT GRANT THE CLAIM if at least one process can not be marked. Implementation –A resource request is only allowed if it results in a SAFE state –The system is always maintained in a SAFE state so eventually all requests will be filled

Ceng Operating Systems Advantages –It works –Allows jobs to proceed when a prevention algorithm wouldn't Problems –Requires there to be a fixed number of resources –What happens if a resource goes down? –Does not allow the process to change its Maximum need while processing

Ceng Operating Systems Safe and Unsafe States (1) Demonstration that the state in (a) is safe (a) (b) (c) (d) (e)

Ceng Operating Systems Safe and Unsafe States (2) Demonstration that the sate in (b) is not safe (a) (b) (c) (d)

Ceng Operating Systems The Banker's Algorithm for a Single Resource Three resource allocation states –safe –unsafe (a) (b) (c)

Ceng Operating Systems Banker's Algorithm for Multiple Resources Example of banker's algorithm with multiple resources

Ceng Operating Systems Deadlock Detection Methods by which the occurrence of deadlock, the processes and resources involved are detected. Generally work by detecting a circular wait The cost of detection must be considered One method is resource allocation graphs

Ceng Operating Systems Deadlock Recovery Recover from the deadlock by removing the offending processes The process being removed may lose work

Ceng Operating Systems A Resource Allocation Graph Example –resource R assigned to process A –process B is requesting/waiting for resource S –process C and D are in deadlock over resources T and U

Ceng Operating Systems Problems Most systems do not support the removal and then restarting of a process. Some processes should NOT be removed. It is possible to have deadlock involving tens or even hundreds of processes

Ceng Operating Systems Implementation –Processes are simply killed off (lost forever) –Usually some sort of priority order exists for killing Support for suspend/resume (rollback) –Some systems come with checkpoint/restart features –Developers indicate a series of checkpoints when designing a software application –So a process only need be rolled back to the last checkpoint, rather than back to the beginning

Ceng Operating Systems Question : What is the simplest and most used method to recover from a deadlock?