Chapter 5 Process Management Understanding Operating Systems, Fourth Edition.

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
Operating Systems Lecture Notes Deadlocks Matthew Dailey Some material © Silberschatz, Galvin, and Gagne, 2002.
Understanding Operating Systems Fifth Edition Chapter 5 Process Management.
Concurrency: Deadlock and Starvation Chapter 6. Deadlock Permanent blocking of a set of processes that either compete for system resources or communicate.
Chapter 6 Concurrency: Deadlock and Starvation
Chapter 6 Concurrency: Deadlock and Starvation
 2004 Deitel & Associates, Inc. All rights reserved. Chapter 7 – Deadlock and Indefinite Postponement Outline 7.1 Introduction 7.2Examples of 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.
Chapter 7 Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts - 7 th Edition, Feb 14, 2005 Chapter 7: Deadlocks 7.1 System Model.
DPNM Lab. Dept. of CSE, POSTECH
Deadlock Chapter 3 R1 R2 P2P1 Allocated Requested.
CSC 322 Operating Systems Concepts Lecture - 29: by
Understanding Operating Systems Sixth Edition
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.
Concurrency: Deadlock & Starvation
CS 450 OPERATING SYSTEMS DEADLOCKS Manju Muralidharan Priya.
Chapter 5 : Process Management
Chapter 6 Concurrency: Deadlock and Starvation
Understanding Operating Systems Sixth Edition
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:
Concurrency: Deadlock and Starvation
Understanding Operating Systems Seventh Edition
Deadlock Chapter 3 Thursday, February 22, Today’s Schedule Assignment #4 from Chapter 3 posted Deadlock - Chapter 3  Skip multiple resources (3.4.2.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Deadlocks.
SWE202 Review. Processes Process State As a process executes, it changes state – new: The process is being created – running: Instructions are being.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 7: Deadlocks.
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.
Operating Systems Part III: Process Management (Deadlocks)
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.
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 ©2013 Operating System Concepts – 9 th Edition Chapter 7: Deadlocks.
CS6502 Operating Systems - Dr. J. Garrido Deadlock – Part 2 (Lecture 7a) CS5002 Operating Systems Dr. Jose M. Garrido.
Process Synchronization
CS 346 – Chapter 7 Deadlock –Properties –Analysis: directed graph Handle –Prevent –Avoid Safe states and the Banker’s algorithm –Detect –Recover.
Chapter 7 Deadlocks Page 2 Chapter 7: Deadlocks System Model Deadlock Characterization Methods for Handling Deadlocks Deadlock Prevention Deadlock Avoidance.
Deadlocks System Model RAG Deadlock Characterization
Styresystemer og Multiprogrammering Block 3, 2005 Deadlocks Robert Glück.
1 OPERATING SYSTEMS DEADLOCKS created by:-gaurav shrivastava contact:- om.
Operating Systems Unit VI Deadlocks and Protection Department of Computer Science Engineering and Information Technology.
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.
Chapter 5 Process Management Semester 2. Objectives  What is a deadlock?  Seven cases of deadlocks  Conditions of deadlocks –Mutual exclusion.
Silberschatz, Galvin and Gagne ©2009 Edited by Khoury, 2015 Operating System Concepts – 9 th Edition, Chapter 7: Deadlocks.
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. 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.
OPERATING SYSTEM CONCEPTS AND PRACTISE
Process Management Deadlocks.
Chapter 5 - Process Management
Operating systems Deadlocks.
ITEC 202 Operating Systems
Chapter 5 Process Management
Chapter 7 – Deadlock and Indefinite Postponement
Operating System: DEADLOCKS
Understanding Operating Systems Seventh Edition
ICS 143 Principles of Operating Systems
Chapter 7 Deadlocks.
Operating systems Deadlocks.
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
Presentation transcript:

Chapter 5 Process Management Understanding Operating Systems, Fourth Edition

2 Objectives You will be able to describe: Several causes of system deadlock The difference between preventing and avoiding deadlocks How to detect and recover from deadlocks The concept of process starvation and how to detect and recover from it

Understanding Operating Systems, Fourth Edition3 Objectives (continued) You will be able to describe: The concept of a race, and how to prevent it The difference between deadlock, starvation, and race

Understanding Operating Systems, Fourth Edition4 Overview A lack of process synchronization results into deadlock or starvation –Deadlock: A system-wide tangle of resource requests that begins when two or more jobs are put on hold Each job waiting for a vital resource to become available The jobs come to a standstill Resolved via external intervention –Starvation: Infinite postponement of a job

Understanding Operating Systems, Fourth Edition5 Deadlock Affects more than one job, hence more serious than starvation System (not just a few programs) is affected as resources are being tied up –e.g., Traffic jam More prevalent in interactive systems Deadlocks quickly become critical situations in real- time systems No simple and immediate solution to a deadlock

Understanding Operating Systems, Fourth Edition6 Deadlock (continued) Figure 5.1: A classic case of traffic deadlock

Understanding Operating Systems, Fourth Edition7 Seven Cases of Deadlock Different cases of Deadlock: –Deadlocks on file requests –Deadlocks in databases –Deadlocks in dedicated device –Deadlocks in multiple device –Deadlocks in spooling –Deadlocks in disk sharing –Deadlocks in a network

Understanding Operating Systems, Fourth Edition8 Case 1: Deadlocks on File Requests Occurs if jobs are allowed to request and hold files for the duration of their execution Example: Refer to Figure 5.2 (next slide) –P1 has access to F1 but requires F2 also –P2 has access to F2 but requires F1 also –Deadlock remains until a program is withdrawn or forcibly removed and its file is released –Any other programs that require F1 or F2 are put on hold as long as this situation continues

Understanding Operating Systems, Fourth Edition9 Case 1: Deadlocks on File Requests (continued) Figure 5.2: A case of deadlock on file requests

Understanding Operating Systems, Fourth Edition10 Case 2: Deadlocks in Databases Occurs if two processes access and lock records in a database Example: Two processes (P1 and P2), each of which needs to update two records (R1 and R2) – Following sequence leads to a deadlock: P1 accesses R1 and locks it P2 accesses R2 and locks it P1 requests R2, which is locked by P2 P2 requests R1, which is locked by P1

Understanding Operating Systems, Fourth Edition11 Case 2: Deadlocks in Databases (continued) Locking: A technique through which the user locks out all other users while working with the database. Can be done at three different levels: –Entire database for the duration of the request –A subsection of the database –Individual record until the request is completed Race between processes: A condition resulting when locking is not used –Causes incorrect final version of data –Depends on order in which each process executes it

Understanding Operating Systems, Fourth Edition12 Case 2: Deadlocks in Databases (continued) Figure 5.3: A case of “race between processes”

Understanding Operating Systems, Fourth Edition13 Case 3: Deadlocks in Dedicated Device Allocation Occurs when there is a limited number of dedicated devices Example: Each program (P1 and P2) needs two tape drives (only available). Soon the following sequence transpires: –P1 requests tape drive 1 and gets it –P2 requests tape drive 2 and gets it –P1 requests tape drive 2 but is blocked –P2 requests tape drive 1 but is blocked

Understanding Operating Systems, Fourth Edition14 Case 4: Deadlocks in Multiple Device Allocation Occurs when several processes request, and hold on to, dedicated devices while other processes act in a similar manner Example: Three programs and three dedicated devices: tape drive, printer, and plotter P1 requests and gets the tape drive P2 requests and gets the printer P3 requests and gets the plotter P1 requests the printer but is blocked P2 requests the plotter but is blocked P3 requests the tape drive but is blocked

Understanding Operating Systems, Fourth Edition15 Case 4: Deadlocks in Multiple Device Allocation (continued) Figure 5.4: Deadlock in multiple device allocation

Understanding Operating Systems, Fourth Edition16 Case 5: Deadlocks in Spooling Virtual device: Sharable device—e.g., a printer transformed by installing a high-speed device, a disk, between it and the CPU Spooling: Disk accepts output from several users and acts as a temporary storage area for all output until printer is ready to accept it Deadlock in spooling: If printer needs all of a job's output before it will begin printing, but spooling system fills available disk space with only partially completed output

Understanding Operating Systems, Fourth Edition17 Case 6: Deadlocks in a Network Occurs when the network doesn’t have protocols to control the flow of messages through the network Example: Refer to Figure 5.5 (next slide) –Consider seven computers on a network, each on different nodes –Direction of the arrows indicates the flow of messages –Deadlock occurs if all the available buffer space fills

Understanding Operating Systems, Fourth Edition18 Case 6: Deadlocks in a Network (continued) Figure 5.5: Deadlock in a network

Understanding Operating Systems, Fourth Edition19 Case 7: Deadlocks in Disk Sharing Occurs when competing processes send conflicting commands to access a disk Example: Refer to Figure 5.6 (next slide) –Two processes are each waiting for an I/O request to be filled: One at cylinder 20 and one at cylinder 310 –Neither can be satisfied because the device puts each request on hold when it tries to fulfill the other

Understanding Operating Systems, Fourth Edition20 Case 7: Deadlocks in Disk Sharing (continued) Figure 5.6: Deadlock in disk sharing

Understanding Operating Systems, Fourth Edition21 Conditions for Deadlock Deadlock preceded by simultaneous occurrence of the following four conditions: –Mutual exclusion –Resource holding –No preemption –Circular wait Removal of only one condition can resolve the deadlock

Understanding Operating Systems, Fourth Edition22 Conditions for Deadlock (continued) Mutual exclusion: Act of allowing only one process to have access to a dedicated resource Resource holding: Act of holding a resource and not releasing it; waiting for the other job to retreat No preemption: Lack of temporary reallocation of resources Circular wait: Each process involved in impasse is waiting for another to voluntarily release the resource so that at least one will be able to continue

Understanding Operating Systems, Fourth Edition23 Modeling Deadlocks Directed graphs: –Processes represented by circles –Resources represented by squares –Solid arrow from a resource to a process means that process is holding that resource –Solid arrow from a process to a resource means that process is waiting for that resource –Direction of arrow indicates flow –If there’s a cycle in the graph then there’s a deadlock involving the processes and the resources in the cycle

Understanding Operating Systems, Fourth Edition24 Modeling Deadlocks (continued) Figure 5.7: Examples of directed graphs

Understanding Operating Systems, Fourth Edition25 Scenario 1 Table 5.1: First scenario’s sequence of events is shown in the directed graph in Figure 5.8.

Understanding Operating Systems, Fourth Edition26 Scenario 1 (continued) Figure 5.8: First scenario The system will stay free of deadlocks if all resources are released before they’re requested by the next process

Understanding Operating Systems, Fourth Edition27 Scenario 2 Table 5.2: Second scenario’s sequence of events is shown in the directed graph in Figure 5.9.

Understanding Operating Systems, Fourth Edition28 Scenario 2 (continued) Figure 5.9: Second scenario Deadlock occurs because every process is waiting for a resource being held by another process, but none will be released without operator intervention

Understanding Operating Systems, Fourth Edition29 Scenario 3 Table 5.3: Third scenario’s sequence of events is shown in the directed graph in Figure 5.10

Understanding Operating Systems, Fourth Edition30 Scenario 3 (continued) Figure 5.10: Third scenario After event 4 the directed graph looks like (a); event 5 breaks the deadlock and the graph soon looks like (b); event 7 breaks the deadlock and the graph soon looks like (c) Resources are released before deadlock can occur

Understanding Operating Systems, Fourth Edition31 Another Example Figure 5.11: (a) A fully allocated cluster of resources; (b) When all three request another unit, deadlock occurs. These graphs can cluster the devices of the same type into one entity, shown by a rectangle The arrows show the links between the single resource and the processes using it

Understanding Operating Systems, Fourth Edition32 Strategies for Handling Deadlocks Strategies to deal with deadlocks include –Prevention: Prevent one of the four conditions from occurring –Avoidance: Avoid the deadlock if it becomes probable –Detection: Detect the deadlock when it occurs and recover from it gracefully

Understanding Operating Systems, Fourth Edition33 Strategies for Handling Deadlocks (continued) Prevention: Necessary to eliminate one of the four conditions, while same condition can’t be eliminated from every resource –Mutual exclusion is necessary Exceptions include devices where mutual exclusion can be bypassed by spooling –Resource holding can be avoided by forcing each job to request, at creation time, every resource it will need Significantly decreases degree of multiprogramming Peripheral devices would be idle

Understanding Operating Systems, Fourth Edition34 Strategies for Handling Deadlocks (continued) –No preemption could be bypassed by allowing OS to deallocate resources from jobs Okay if state of job can be easily saved and restored Not accepted to preempt dedicated I/O device or files during modification –Circular wait can be bypassed if the operating system prevents the formation of a circle Use scheme of hierarchical ordering –Requires that jobs anticipate order in which they will request resources –Difficult to satisfy all users

Understanding Operating Systems, Fourth Edition35 Avoidance Deadlock can be avoided if system knows ahead of time sequence of requests associated with each of the active processes Dijkstra’s Bankers Algorithm (1965) regulates resources allocation to avoid deadlock –No customer granted loan exceeding bank’s total capital –All customers given a maximum credit limit –No customer allowed to borrow over the limit –The sum of all loans won’t exceed bank’s total capital

Understanding Operating Systems, Fourth Edition36 Avoidance (continued) Table 5.4: The bank started with $10,000 and has remaining capital of $4,000 after these loans Safe state: Bank still has enough money left after loans to satisfy the maximum requests of C1, C2, or C3

Understanding Operating Systems, Fourth Edition37 Avoidance (continued) Table 5.5: The bank has remaining capital of only $1,000 after these loans and therefore is in an “unsafe state” Unsafe state: Bank has not enough money left after loans to satisfy the maximum requests of C1, C2, or C3

Understanding Operating Systems, Fourth Edition38 Avoidance (continued) Table 5.6: A safe state: six devices are allocated and four units are still available Same banking principles can be applied to an operating system

Understanding Operating Systems, Fourth Edition39 Avoidance (continued) Table 5.7: An unsafe state: only one unit is available but every job requires at least two to complete its execution

Understanding Operating Systems, Fourth Edition40 Avoidance (continued) To avoid deadlock, OS must make sure: –Never satisfy a request that moves it from a safe state to an unsafe one –Must identify the job with the smallest number of remaining resources –Number of available resources is always equal to, or greater than, the number needed for the selected job to run to completion

Understanding Operating Systems, Fourth Edition41 Avoidance (continued) Problems with Banker’s Algorithm: –Jobs must state the maximum number of resources needed –Number of total resources for each class must remain constant –Number of jobs must remain fixed –Overhead cost incurred can be quite high –Resources aren’t well utilized because the algorithm assumes the worst case –Scheduling suffers as a result of poor utilization and jobs are kept waiting for resource allocation

Understanding Operating Systems, Fourth Edition42 Detection Deadlocks can be detected by building directed resource graphs and looking for cycles Algorithm used to detect circularity can be executed whenever it is appropriate The detection algorithm: 1.Remove a process that is currently using a resource and not waiting for one 2.Remove a process that’s waiting only for resource classes that aren’t fully allocated 3.Go back to Step 1 and continue with Steps 1 and 2 until all connecting lines have been removed

Understanding Operating Systems, Fourth Edition43 Detection (continued) Figure 5.12: Deadlock-free system because the graph can be completely reduced, as shown in (d)

Understanding Operating Systems, Fourth Edition44 Recovery Deadlock must be untangled once detected, so the system returns to normal quickly All recovery methods have at least one victim Recovery Methods: –Terminate every job that’s active in the system and restart them from the beginning –Terminate only the jobs involved in the deadlock and ask their users to resubmit them –Identify jobs involved in deadlock and terminate them one at a time

Understanding Operating Systems, Fourth Edition45 Recovery (continued) (continued): –Jobs that keep a record (snapshot) of their progress can be interrupted –Select a nondeadlocked job, preempt its resources, allocate them to a deadlocked process –Stop new jobs from entering system, which allows nondeadlocked jobs to run to completion so they’ll release their resources (no victim)

Understanding Operating Systems, Fourth Edition46 Recovery (continued) Select the victim that will have the least-negative effect on the system Factors to be considered to select a victim: –Priority of job under consideration: high-priority jobs are usually untouched –CPU time used by job: jobs close to completion are usually left alone –Number of other jobs that would be affected if this job were selected as the victim –Jobs that are modifying data shouldn’t be selected for termination

Understanding Operating Systems, Fourth Edition47 Starvation Job is prevented from execution as it’s kept waiting for resources that never become available –Result of conservative allocation of resources Example: –“The dining philosophers table” Dijkstra (1968) To avoid starvation: –Implement algorithm to track how long each job has been waiting for resources (aging) –Block new jobs until the starving jobs have been satisfied

Understanding Operating Systems, Fourth Edition48 Starvation (continued) Figure 5.14: Starvation — The dining philosophers’ table Each philosopher must have two forks to begin eating, one on right and one on left Unless forks (resources), are allocated fairly, some philosophers may starve

Understanding Operating Systems, Fourth Edition49 Summary Every operating system must dynamically allocate a limited number of resources while avoiding the two extremes of deadlock and starvation Several methods of dealing with deadlocks include prevention, avoidance, and detection and recovery Deadlocks can be prevented by not allowing at least one of the four conditions of a deadlock to occur in the system at the same time as the others Prevention algorithms are complex and involve high overhead to routinely execute them

Understanding Operating Systems, Fourth Edition50 Summary (continued) Deadlocks can be avoided by clearly identifying safe states and unsafe states System should keep enough resources in reserve to guarantee that all jobs can run to completion In an avoidance policy, system’s resources aren’t allocated to their fullest potential System must be prepared to detect and recover from the deadlocks Detection option usually relies on the selection of at least one “victim”