Operating System Concepts and Techniques Lecture 15 Deadlock and starvation-1 M. Naghibzadeh Reference M. Naghibzadeh, Operating System Concepts and Techniques,

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.
ICS Principles of Operating Systems Lectures 8 and 9 - Deadlocks Prof. Dmitri V. Kalashnikov dvk ics.uci.edu Slides © Prof. Nalini Venkatasubramanian.
Lecture 7: Deadlock     Necessary Conditions for Deadlock     Deadlock Prevention - Havender's Linear Ordering Deadlock Avoidance Deadlock Detection &
MODERN OPERATING SYSTEMS Third Edition ANDREW S
Ceng Operating Systems Chapter 2.4 : Deadlocks Process concept  Process scheduling  Interprocess communication  Deadlocks Threads.
 2004 Deitel & Associates, Inc. All rights reserved. Chapter 7 – Deadlock and Indefinite Postponement Outline 7.1 Introduction 7.2Examples of Deadlock.
EEE 435 Principles of Operating Systems Deadlock Avoidance, Prevention, and Wrap-Up (Modern Operating Systems 3.5, 3.6, and 3.7)
Operating Systems COMP 4850/CISG 5550 Deadlock Avoidance Dr. James Money.
7.4 Resource Concepts Preemptible resources (e.g. processors and main memory) –Can be removed from a process without loss of work Nonpreemptible resources.
Chapter 3 Deadlocks TOPICS Resource Deadlocks The ostrich algorithm
MODERN OPERATING SYSTEMS Third Edition ANDREW S. TANENBAUM Chapter 6 Deadlocks Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All.
1 Deadlocks Chapter Resource 3.2. Introduction to deadlocks 3.3. The ostrich algorithm 3.4. Deadlock detection and recovery 3.5. Deadlock avoidance.
With slides from C. Griwodz, K. Li, A. Tanenbaum and M. van Steen
Avishai Wool lecture Introduction to Systems Programming Lecture 5 Deadlocks.
DPNM Lab. Dept. of CSE, POSTECH
Deadlock Chapter 3 R1 R2 P2P1 Allocated Requested.
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.
Deadlocks. 2 System Model There are non-shared computer resources –Maybe more than one instance –Printers, Semaphores, Tape drives, CPU Processes need.
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.
1 Lecture 8: Deadlocks Operating System Spring 2008.
Chapter 3 Deadlocks 3.1. Resource 3.2. Introduction to deadlocks
02/19/2008CSCI 315 Operating Systems Design1 Deadlock Notice: The slides for this lecture have been largely based on those accompanying the textbook Operating.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 7: Deadlocks.
What we will cover…  The Deadlock Problem  System Model  Deadlock Characterization  Methods for Handling Deadlocks  Deadlock Prevention  Deadlock.
Deadlock Chapter 3 Thursday, February 22, Today’s Schedule Assignment #4 from Chapter 3 posted Deadlock - Chapter 3  Skip multiple resources (3.4.2.
Deadlock Questions answered in this lecture: What are the four necessary conditions for deadlock? How can deadlock be prevented? How can deadlock be avoided?
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.
1 MODERN OPERATING SYSTEMS Third Edition ANDREW S. TANENBAUM Chapter 6 Deadlocks Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc.
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.
MODERN OPERATING SYSTEMS Third Edition ANDREW S. TANENBAUM Chapter 6 Deadlocks Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All.
CS6502 Operating Systems - Dr. J. Garrido Deadlock – Part 2 (Lecture 7a) CS5002 Operating Systems Dr. Jose M. Garrido.
CS 346 – Chapter 7 Deadlock –Properties –Analysis: directed graph Handle –Prevent –Avoid Safe states and the Banker’s algorithm –Detect –Recover.
Lecture 12 Handling Deadlock – Prevention, avoidance and detection.
Chapter 8 Deadlocks. Objective System Model Deadlock Characterization Methods for Handling Deadlocks Deadlock Prevention Deadlock Avoidance Deadlock Detection.
Deadlocks Copyright ©: University of Illinois CS 241 Staff1.
Operating System Concepts and Techniques Lecture 16 Deadlock and starvation-2 M. Naghibzadeh Reference M. Naghibzadeh, Operating System Concepts and Techniques,
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);
Deadlock Operating Systems (CC2011NI) -Mr. Pranoy Man Pradhan.
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.
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.
MODERN OPERATING SYSTEMS Third Edition ANDREW S
Deadlock Management.
Chapter 6 : Deadlocks What is a Deadlock?
Advanced Operating System Fall 2009
Lecture 19: Deadlock: Conditions, Detection and Avoidance
Banker`s Algorithm Developed by Dijkstra in 1965
MODERN OPERATING SYSTEMS Third Edition ANDREW S
The relation between the process and
Chapter 3 Deadlocks 3.1. Resource 3.2. Introduction to deadlocks
DEADLOCK.
Lecture 19: Deadlock: Conditions, Detection and Avoidance
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
CSCI 315 Operating Systems Design
MODERN OPERATING SYSTEMS Third Edition ANDREW S
Presentation transcript:

Operating System Concepts and Techniques Lecture 15 Deadlock and starvation-1 M. Naghibzadeh Reference M. Naghibzadeh, Operating System Concepts and Techniques, First ed., iUniverse Inc., To order: or

Deadlock and Starvation Deadlock is an standstill situation in which two or more processes are unable to proceed because of each process is waiting for something from another process and a closed wait-for cycle is formed For example, if two people one has a pencil and the other one a sheet of paper and each one needs the other’s resource which will never receive a deadlock occurs 2

Deadlock conditions There are three necessary conditions for deadlock to occur 1. Mutual exclusion: there are resources in the system for which mutual exclusion is enforced to prevent race condition 2. Hold and wait (or partial allocation): A situation in which a process is holding one or more resources and is also waiting for one or more other resources that are not available for the time being 3. Non-preemptable resources: A resource that cannot be forcibly taken away from the holder process without imposing any intolerable harm to the process One sufficient condition for deadlock 1. The existence of a wait-for closed cycle, when this happens it means the three necessary conditions also hold 3

Deadlock modeling To graphically show deadlock opposite symbols are used The following closed wait- for graph shows a deadlock 4 A process A resource A process waiting for a resource A resource is taken by a process scanner A B CD drive

Solutions for deadlock problem There are four policies to attack deadlock  Ignoring Deadlock  Deadlock Prevention  Deadlock Avoidance  Deadlock Detection and Recovery Ignoring deadlock (or ostrich algorithm): we are not actually suggesting a solution, but rather erasing a problem statement It does not mean deadlock will not occur The side effects of such an action could be very harmful It is not wise to ignore deadlock in sensitive environments 5

Deadlock Prevention For deadlock prevention, we can arrange that at least one of the conditions is not satisfied By not enforcing mutual exclusion, we allow race conditions to occur; this is not acceptable Removing the hold-and-wait is possible; do not allow a process to wait for a new resource while holding other resources (preemptable resources are exempted)  Assign all the needed resource of a process at start or not accept this process Disadvantages:  Inefficient use of resources  Must declare all its needed resources at the start 6

Deadlock Prevention… Removing the non-preemptability Not possible, some resources are naturally non-preemptable Removing the circular-wait One method is to use resource ordering  All (non-preemptable) resources are clustered into n ordered classes  If a process is given a resource from class i, it can only request resources from classes of a higher order  Resources possessed by a process must be returned in a descending order Disadvantages:  Inefficient use of resources but much better than removing hold and wait  Must declare all its needed resources at the start 7

Deadlock Prevention… Semi-Proof of deadlock freeness by showing a two-process case Example: a Process will need resources 5, 18, 13, 20, 22, 28, 32, 45, during its execution 1- Resource number 13 is requested // OS will allocate resources 5, 8, and Resource number 22 is requested // OS will allocate resources 20 and Resource number 22 is released // OS will take back this resource 4- Resource number 45 is requested // OS will allocate resources 22, 28, 32, and Resource number 28 is released // OS will not take back this resource because the process still possesses resources 32 and Resources number 32 and 45 are released // OS will take back resource numbers 45, 32, and Resource number 22 is released // OS will take back this resource 8

Deadlock Avoidance Deadlock avoidance ensures that deadlock will not occur Deadline avoidance is based on careful analysis of every request by examining what will happen in the future if the requested resource is allocated The resource is allocated if the system will be safe and will not be allocated otherwise. If not allocated, the requesting process withdraws its request and resubmits it at a later time One of the most respected deadline avoidance methods is the banker’s algorithm formalized by Dijkstra 9

Deadlock Avoidance - Banker’s algorithm Think of a bank branch that has certain amount of cash capital (resources) and an intelligent manager Its capital will not increase The banker grants credit to customers who need a loan The total sum of all credits is greater than the bank’s capital, otherwise the system is safe anyways Customers may claim all their credit at once or in a number of installments The banker is not allowed to forcibly collect the money from a customer (non-preemptable) 10

Deadlock Avoidance - Banker’s algorithm… The banker carefully checks every request to make sure by lending the amount he will not encounter deadlock A deadlock will occur when lending a requested amount leads to a situation in which there is no way to complete total needs of all customers, no matter what the future ordering of the requests would be A safe request is one which will not cause deadlock An unsafe request will not be granted 11

Banker’s algorithm 1. If the number of requested resources is greater than the number of available resources the request is not valid; return from this algorithm; otherwise continue with the next step 2. Suppose that the required resources are given to the process (it is not actually given) 3. See if there is a process that can complete its job with the available resources; if there is one, mark it as completed; suppose that all of its resources are taken back and are added to available resources; repeat this step for unmarked processes until there are no more unmarked processes or there is no process left that can complete its job with the available resources 4. If all processes are marked, it is safe to allocate the requested resources to the process; otherwise declare that the allocation is unsafe and return 12

Banker’s algorithm Example: Suppose the number of simultaneously opened files is restricted to 128 four processes in the system that need to simultaneously open, in the worst case, 55, 95, 10, and 80 files, respectively Total need is =240 Next slide is a scenario of requests 13

Banker’s algorithm-example 1. Process p1 needs to open 20 files 2. Process p3 needs to open 2 files 3. Process p1 needs to open 15 files 4. Process p4 needs to open 25 files 5. Process p3 needs to open 3 files 6. Process p2 needs to open 47 files 7. Process p4 needs to open 7 files 8. Process p3 needs to open 5 files 9. Process p2 needs to open 33 files 10. Process p1 needs to open 20 files 11. Process p4 needs to open 30 files 12. Process p4 needs to open 18 files 13 Process p2 needs to open 15 files 14

Banker’s algorithm-example… 15 Step no.ProcessRequestGiven, so far Will need in the future Available, overall Safety 0128Safe 1P Safe 2p Safe 3p Safe 4p Safe 5p332566Safe 6p Safe 7p Unsafe

Summary Controlled usage of shared resources, by guaranteeing mutual exclusion to prevent race condition, causes an important undesirable side effects called deadlock There are four different policies for attacking deadlocks: ignoring deadlock, deadlock prevention, deadlock avoidance, and deadlock detection and recovery The first policy erases the problem statement altogether The second and third policy forestall deadlock from happening, even though the system usually pays a high price for this 16

17 Find out The exact difference between deadlock prevention and deadlock avoidance As many non-preemptable resources as you can As many preemptable resources as you can Whether there could be a closed circular wait which includes main memory when memory management is virtual memory There cannot be a deadlock with only one process Other policies for preventing deadlock, like wait- wound

18 Any questions?