Deadlock Chapter 3 R1 R2 P2P1 Allocated Requested.

Slides:



Advertisements
Similar presentations
Deadlocks Today Resources & deadlocks Dealing with deadlocks Other issues Next Time Memory management.
Advertisements

MODERN OPERATING SYSTEMS Third Edition ANDREW S
Ceng Operating Systems Chapter 2.4 : Deadlocks Process concept  Process scheduling  Interprocess communication  Deadlocks Threads.
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.
Tanenbaum Ch 6 Silberschatz Ch 7
5/25/2015Page 1 Deadlock Management B. Ramamurthy.
DEADLOCK.
Chapter 3 Deadlocks - Αδιέξοδα 3.1. Resource
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
Deadlocks Tore Larsen With slides from T. Plagemann, C. Griwodz, K. Li, A. Tanenbaum and M. van Steen.
Mehdi Naghavi Spring 1386 Operating Systems Mehdi Naghavi Spring 1386.
Chapter 3: Deadlocks Chapter 3 2 CMPS 111, UC Santa Cruz Overview  Resources  Why do deadlocks occur?  Dealing with deadlocks Ignoring them: ostrich.
Deadlocks. 2 System Model There are non-shared computer resources –Maybe more than one instance –Printers, Semaphores, Tape drives, CPU Processes need.
The Banker’s Algorithm for A Single Resource
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.
Chapter 3 Deadlocks 3.1. Resource 3.2. Introduction to deadlocks
CS450/550 Deadlocks.1 Adapted from MOS2E UC. Colorado Springs CS450/550 Operating Systems Lecture 3 Deadlocks Palden Lama Department of Computer Science.
Chapter 3 Chapter 3: Deadlocks Chapter 3 2 CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt) Overview Resources Why do.
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 Processes, Threads, Race Conditions & Deadlocks Operating Systems Review.
CH 3 Deadlock When 2 (or more) processes remain blocked forever!
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. CMPS 111, Fall Overview ✦ Resources ✦ Why do deadlocks occur? ✦ Dealing with deadlocks Ignoring them: ostrich algorithm Detecting.
Chapter 7 – Deadlock (Pgs 283 – 306). Overview  When a set of processes is prevented from completing because each is preventing the other from accessing.
Overview Resources Why do deadlocks occur? Dealing with deadlocks Ignoring them: ostrich algorithm Detecting & recovering from deadlock Avoiding deadlock.
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.
1 Pertemuan 10 Deadlock (lanjutan) Matakuliah: T0316/sistem Operasi Tahun: 2005 Versi/Revisi: 5.
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.
Operating Systems (OS)
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.
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.
CSC 322 Operating Systems Concepts Lecture - 28: by Ahmed Mumtaz Mustehsan Special Thanks To: Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall,
Deadlocks System Model RAG Deadlock Characterization
Operating Systems COMP 4850/CISG 5550 Deadlocks Dr. James Money.
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.
CH 3 Deadlock When 2 (or more) processes remain blocked forever!
Copyright ©: Nahrstedt, Angrave, Abdelzaher1 Deadlock.
Deadlocks References –text: Tanenbaum ch.3. Deadly Embrace Deadlock definition –A set of process is dead locked if each process in the set is waiting.
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.
Process Management Deadlocks.
CSE 120 Principles of Operating
Deadlock Management.
Chapter 6 : Deadlocks What is a Deadlock?
Deadlocks References text: Tanenbaum ch.3.
Lecture 19: Deadlock: Conditions, Detection and Avoidance
Deadlocks References text: Tanenbaum ch.3.
Chapter 3 Deadlocks 3.1. Resource 3.2. Introduction to deadlocks
DPNM Lab. Dept. of CSE, POSTECH
MODERN OPERATING SYSTEMS Third Edition ANDREW S
Chapter 3 Deadlocks 3.1. Resource 3.2. Introduction to deadlocks
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
Deadlocks References text: Tanenbaum ch.3.
Presentation transcript:

Deadlock Chapter 3 R1 R2 P2P1 Allocated Requested

Resources Processes compete for system resources –CPU cycles –I/O devices –Printers –Tape drives –Files –Tables –Database records

Resources: Preemptible vs. Nonpreemptible Preemptible –Can be taken away from a process without ill effect Examples? Nonpreemptible –Taking it away from a process causes the process to fail We are concerned with nonpreemptable resources

How a process relates to a (nonpreemptible) resource It requests the resource –What can it do if it isn’t available? It uses the resource It releases the resource, making it available to another process

Using a semaphore to protect resources One resourceTwo resources

Using semaphores to protect resources Deadlock-freeDeadlock-prone

The problem of deadlock If a process is waiting for a resource that is held by another process that is waiting for another resource held by another process… –A set of processes is in a deadlocked state when every process is waiting for an event that can be caused only by another process in the set

The four necessary conditions for deadlock to occur Mutual exclusion –the resource can be used by only one process at a time Hold & wait or resource holding –processes are permitted to hold onto their current resources while they wait for others No preemption –no process can bump another for its resource Circular wait –can show that there is a cycle

Resource allocation graphs for deadlock modeling a) Resource R is assigned to Process A b) Process B is waiting for Resource S c) Processes C & D are in deadlock over Resources T & U

Creating deadlock ABC

Avoiding deadlock

Addressing the issue of deadlock Ignorance –Ostrich algorithm Detection & recovery –Scan the system looking for cycles of hold & wait –Implement recovery algorithms Avoidance –If it seems that deadlock is a possibility, do something to keep it from happening Prevention – negate one of the four necessary conditions

Ignorance: 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

Deadlock detection in a graph Find a process not waiting for any resource. –Remove its allocation arrows & reallocate its resources Find a process that is waiting only for resources that are not completely allocated. –Remove these allocation arrows & reallocate the resources Repeat until all lines have been removed or you determine that they cannot all be removed.

Resource graph: detection with one resource of each type A cycle can be found within the graph, denoting deadlock T

Resource graph: detection with multiple resources of each type R1R3 R2R4 P1P2P3

Data structures needed for detection with multiple resources of each type n Σ C ij + A j = E j i=1 Fig. 3-6

Detection with multiple resources of each type Resources in existenceResources available See pp

Recovery from deadlock Recovery through preemption –take a resource from some other process –depends on nature of the resource Recovery through rollback –checkpoint a process periodically –use this saved state –restart the process if it is found deadlocked

Recovery from deadlock Recovery through killing processes –crudest but simplest way to break a deadlock –kill one of the processes in the deadlock cycle –the other processes get its resources –choose process that can be rerun from the beginning

Avoidance – Banker’s algorithm Use an algorithm similar to what a bank uses to ensure that it always has funds on hand to satisfy its customers’ eventual needs –Each process must state upfront what its maximum resource needs will be Deal with safe and unsafe states –avoid unsafe states Working with multiple instances of resources

Safe state State (a) is safe because It is not deadlocked There is a scheduling order for each process to run to completion (a) (b) (c) (d) (e) We have a total of 10 instances of a given resource, with processes A, B, C holding & eventually needing what is indicated here:

Unsafe states State (b) is unsafe because There is no way to satisfy all processes after it (a) (b) (c) (d)

Banker's Algorithm for multiple instances of a single resource (a) (b) (c) Are each of these states safe or unsafe?

Banker's Algorithm for multiple resources

Prevention Don’t allow mutual exclusion Eliminate resource holding Allow preemption Modify circular wait

Preventing the “mutual exclusion” condition Devices, such as printer, can be spooled –only the printer daemon uses printer resource –thus deadlock for printer eliminated But not all devices can be spooled, so abide by the principle: –Allow as few processes as possible to actually claim the resource

Preventing the “hold and wait” condition Require processes to request all resources before starting –Then, a process never has to wait for what it needs Problems –Process may not know required resources at start –Ties up resources other processes could be using

Preventing the “no preemption” condition This is not usually a viable option Consider a process given the printer –halfway through its job –now forcibly take away printer –!!??

Preventing the “circular wait” condition Order resources Allocate in order

Summary of approaches to deadlock prevention

Related issues Two-phase locking in databases Deadlocking on semaphores Starvation in CPU scheduling