Understanding Operating Systems Seventh Edition

Slides:



Advertisements
Similar presentations
Chapter 6 Concurrency: Deadlock and Starvation Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community.
Advertisements

Deadlock and Starvation
Lecture 6 :Deadlocks. Deadlock Permanent blocking of a set of processes that either compete for system resources or communicate with each other Involves.
Operating Systems Lecture Notes Deadlocks Matthew Dailey Some material © Silberschatz, Galvin, and Gagne, 2002.
Understanding Operating Systems Fifth Edition Chapter 5 Process Management.
Chapter 6 Concurrency: Deadlock and Starvation Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community.
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.
Understanding Operating Systems Sixth Edition
The Banker’s Algorithm for A Single Resource
Concurrent Processes Lecture 5. Introduction Modern operating systems can handle more than one process at a time System scheduler manages processes and.
Concurrency: Deadlock & Starvation
CS 450 OPERATING SYSTEMS DEADLOCKS Manju Muralidharan Priya.
OS Spring 2004 Concurrency: Principles of Deadlock Operating Systems Spring 2004.
Chapter 5 : Process Management
OS Fall’02 Concurrency: Principles of Deadlock Operating Systems Fall 2002.
1 Concurrency: Deadlock and Starvation Chapter 6.
Chapter 6 Concurrency: Deadlock and Starvation
Understanding Operating Systems Sixth Edition
Understanding Operating Systems Sixth Edition
Concurrency: Deadlock and Starvation Chapter 6. Goal and approach Deadlock and starvation Underlying principles Solutions? –Prevention –Detection –Avoidance.
1 Concurrency: Deadlock and Starvation Chapter 6.
Concurrency: Deadlock and Starvation
Chapter 6 Concurrency: Deadlock and Starvation Operating Systems: Internals and Design Principles, 6/E William Stallings Dave Bremer Otago Polytechnic,
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.
Chapter 5 Process Management Understanding Operating Systems, Fourth Edition.
SWE202 Review. Processes Process State As a process executes, it changes state – new: The process is being created – running: Instructions are being.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Introduction to Concurrency.
1 Announcements The fixing the bug part of Lab 4’s assignment 2 is now considered extra credit. Comments for the code should be on the parts you wrote.
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 ©2013 Operating System Concepts – 9 th Edition Chapter 7: Deadlocks.
CIS Operating Systems Deadlock Professor Qiang Zeng Fall 2015.
Process Synchronization
Deadlocks.  Deadlocks: Occurs when threads are waiting for resources with circular dependencies Often involve nonpreemptable resources, which cannot.
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.
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.
Informationsteknologi Monday, October 1, 2007Computer Systems/Operating Systems - Class 111 Today’s class 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);
Damian Gordon.  What are good policies to schedule processes?
Understanding Operating Systems Seventh Edition
Process Management Deadlocks.
Chapter 5 - Process Management
Operating systems Deadlocks.
G.Anuradha Reference: William Stallings
Chapter 6 Concurrent Processes
ITEC 202 Operating Systems
Chapter 5 Process Management
Virtual Memory Networks and Communication Department.
Chapter 7 – Deadlock and Indefinite Postponement
Operating System: DEADLOCKS
Chapter 7 Deadlocks.
Chapter 7: Deadlocks.
Chapter 7: Deadlocks.
Operating systems Deadlocks.
G.Anuradha Ref:- Galvin
Concurrency: Mutual Exclusion and Process Synchronization
Deadlocks Session - 13.
Processor Scheduling Damian Gordon.
CSE 542: Operating Systems
CSE 542: Operating Systems
Deadlock CSE 2431: Introduction to Operating Systems
Presentation transcript:

Understanding Operating Systems Seventh Edition Chapter 5 & 6 Combined

Understanding Operating Systems Seventh Edition Chapter 6 Concurrent Processes

Learning Objectives After completing this chapter, you should be able to describe: The critical difference between processes and processors and how they’re connected The differences among common configurations of multiprocessing systems The basic concepts of multicore processor technology Understanding Operating Systems, 7e

Learning Objectives (cont'd.) The essential ideas behind process synchronization software The need for process cooperation when several processors work together How processors cooperate when executing a job, process, or thread The significance of concurrent programming Understanding Operating Systems, 7e

Overview Processing Programs (processes) Processors Multiprogramming 2+ 1 Parallel / Multiprocessing Concurrent processing Understanding Operating Systems, 7e

What Is Parallel Processing? Parallel processing \ multiprocessing Two or more processors operate in one system at the same time – multiple processors running multiple programs (processes) Work may or may not be related Two or more CPUs execute instructions simultaneously Processor Manager Coordinates activity of each processor Synchronizes interaction among CPUs Understanding Operating Systems, 7e

What Is Parallel Processing? (cont'd.) Benefits Increased reliability More than one CPU If one processor fails, others take over: must be designed into the system Faster processing Instructions processed in parallel two or more at a time Understanding Operating Systems, 7e

What Is Parallel Processing? (cont'd.) Faster instruction processing methods CPU allocated to each program or job CPU allocated to each working set or parts of it Individual instructions subdivided Each subdivision processed simultaneously Concurrent programming Two major challenges Connecting processors into configurations Orchestrating processor interaction Example: six-step information retrieval system Synchronization is key Understanding Operating Systems, 7e

Understanding Operating Systems, 7e (table 6.1) The six steps of the four-processor fast food lunch stop. © Cengage Learning 2014 Understanding Operating Systems, 7e

Levels of Multiprocessing Multiprocessing occurs at three levels Job level Process level Thread level Each level requires different synchronization frequency Understanding Operating Systems, 7e

Levels of Multiprocessing (cont'd.) (table 6.2) Typical levels of parallelism and the required synchronization among processors. © Cengage Learning 2014 Understanding Operating Systems, 7e

Introduction to Multi-Core Processors Multi-core processing Several processors placed on single chip Problems Current leakage (tunneling) and heat Solution Single chip with two processor cores in same space Allows two sets of simultaneous calculations Two cores each run more slowly than single core chip Understanding Operating Systems, 7e

Process Synchronization Software Successful process synchronization Lock up used resource Protect from other processes until released Only when resource is released Waiting process is allowed to use resource Mistakes in synchronization can result in: Starvation Leave job waiting indefinitely Deadlock If key resource is being used Understanding Operating Systems, 7e

Process Cooperation Several processes work together to complete common task Each case requires Mutual exclusion and synchronization Example Producers and consumers problem Each case implemented using semaphores Understanding Operating Systems, 7e

Concurrent Programming Another type of multiprocessing Concurrent processing system One program (process) using multiple processors Executes sets of instructions in parallel Requires programming language and computer system support Understanding Operating Systems, 7e

Threads and Concurrent Programming Threads: lightweight processes Smaller unit within process Scheduled and executed Minimizes overhead Swapping process between main memory and secondary storage Each active process thread Processor registers, program counter, stack, and status Shares data area and resources allocated to its process Understanding Operating Systems, 7e

Threads and Concurrent Programming (cont'd.) Web server: improved performance and interactivity with threads Requests for images or pages: each served with a different thread After thread’s task completed: thread returned to pool for assignment to another task Understanding Operating Systems, 7e

Conclusion Multiprocessing: several configurations Single-processor with interacting processes obtain control of CPU at different times Multiple processors synchronized by Process Manager Synchronize processes using hardware and software mechanisms Avoid typical problems of synchronization Missed waiting customers Synchronization of producers and consumers Mutual exclusion of readers and writers Concurrent processing innovations Threads and multi-core processors Understanding Operating Systems, 7e

Conclusion (cont'd.) Avoid typical problems of synchronization Missed waiting customers Synchronization of producers and consumers Mutual exclusion of readers and writers Concurrent processing innovations Threads and multi-core processors Understanding Operating Systems, 7e

Understanding Operating Systems Seventh Edition Chapter 5 Process Management

Learning Objectives After completing this chapter, you should be able to describe: The differences among deadlock, race, and starvation Several causes of system deadlock and livelock The difference between preventing and avoiding deadlocks How to detect and recover from deadlocks How to detect and recover from starvation The concept of a race and how to prevent it Understanding Operating Systems, 7e

Introduction Resource sharing perspectives Memory management and processor sharing Many programs competing for limited resources Lack of process synchronization consequences Deadlock: “deadly embrace,” “Catch 22,” “blue screen of death,” etc. Two or more jobs placed in HOLD state Jobs waiting for unavailable vital resource System comes to standstill Unresolved by OS: requires external intervention Understanding Operating Systems, 7e

Deadlock, Livelock, and Starvation Narrow staircase analogy Staircase = system; steps and landings = resources Stairs: only wide enough for one person Landing at each floor: room for two people Deadlock: two people meet on the stairs Neither retreats Livelock: two people on a landing Each time one takes a step to the side, the other mirrors that step; neither moves forward Starvation: people wait on landing for a break Break never comes Understanding Operating Systems, 7e

Deadlock More serious than starvation Affects entire system Affects more than one job Not just a few programs All system resources become unavailable More prevalent in interactive systems Real-time systems Deadlocks quickly become critical situations OS must prevent or resolve Understanding Operating Systems, 7e

Seven Cases of Deadlock or Livelock Nonsharable/nonpreemptable resources Allocated to jobs requiring same type of resources Resource types locked by competing jobs File requests Databases Dedicated device allocation Multiple device allocation Spooling Network Disk sharing Understanding Operating Systems, 7e

Case 1: Deadlocks on File Requests Jobs request and hold files for execution duration Example (Figure 5.2) Two programs (P1, P2) and two files (F1, F2) Deadlock sequence P1 has access to F1 and also requires F2 P2 has access to F2 and also requires F1 Deadlock remains until: One program is closed or One program is forcibly removed and file is released Other programs requiring F1 or F2 Put on hold for duration of situation (figure 5.2) Case 1. These two processes, shown as circles, are each waiting for a resource, shown as rectangles, that has already been allocated to the other process, thus creating a deadlock. © Cengage Learning 2014 Understanding Operating Systems, 7e

Case 2: Deadlocks in Databases (figure 5.3) Case 2. P1 finishes first and wins the race but its version of the record will soon be overwritten by P2. Regardless of which process wins the race, the final version of the data will be incorrect. © Cengage Learning 2014 Two processes access and lock database records Locking Guarantees data integrity One user locks out all other database users Three locking levels Entire database for duration of request Subsection of database Individual record until request completed Example: two processes (P1 and P2) Each needs to update two records (R1 and R2) Deadlock sequence P1 accesses R1 and locks it P2 accesses R2 and locks it P1 requests R2 but locked by P2 P2 requests R1 but locked by P1 Race between processes Results when locking not used Causes incorrect final version of data Depends on process execution order Understanding Operating Systems, 7e

Case 3: Deadlocks in Dedicated Device Allocation Limited number of dedicated devices Example Two administrators each running education programs with processes P1 and P2, respectively Need two audio recorders each Only two audio recorders (R1 and R2) available Deadlock sequence P1 requests tape R1 and gets it P2 requests tape R2 and gets it P1 requests tape R2 but blocked P2 requests tape R1 but blocked Understanding Operating Systems, 7e

Case 4: Deadlocks in Multiple Device Allocation (figure 5.4) Case 4. Three processes, shown as circles, are each waiting for a device that has already been allocated to another process, thus creating a deadlock. © Cengage Learning 2014 Several processes request & hold dedicated devices Example (Figure 5.4) Three programs (P1, P2, P3) Three dedicated devices (scanner, printer, plotter) Deadlock sequence P1 requests and gets scanner P2 requests and gets printer P3 requests and gets the plotter P1 requests printer but blocked P2 requests plotter but blocked P3 requests scanner but blocked Understanding Operating Systems, 7e

Case 5: Deadlocks in Spooling Deadlock sequence Printer needs all job output before printing begins Spooling system fills disk space area No one job has entire print output in spool area Results in partially completed output for all jobs Results in deadlock Virtual device Dedicated device made sharable Example Printer: high-speed disk device transfers data between printer and CPU Spooling Process Spooler accepts output from several users Acts as temporary storage for output Output resides in spooling system until printer accepts job data Understanding Operating Systems, 7e

Case 6: Deadlocks in a Network No network protocols controlling network message flow Example (Figure 5.5) Seven computing devices on network Each on different nodes Direction of arrows Indicates communication flow Deadlock sequence All available buffer space fills (figure 5.5) Case 6, deadlocked network flow. Notice that only two nodes, C1 and C2, have buffers. Each line represents a communication path. The arrows indicate the direction of data flow. © Cengage Learning 2014 Understanding Operating Systems, 7e

Case 7: Deadlocks in Disk Sharing Competing processes send conflicting commands Scenario: disk access resulting in livelock Example (Figure 5.6) Two processes Each process waiting for I/O request One at Track 20 and one at Track 310 Deadlock sequence Arm moves back and forth between Tracks 20 and 310 attempting to fulfill the two competing commands Neither I/O request is satisfied (figure 5.6) Case 7. Two processes are each waiting for an I/O request to be filled: one at track 20 and one at track 310. But by the time the read/write arm reaches one track, a competing command for the other track has been issued, so neither command is satisfied and livelock occurs. © Cengage Learning 2014 Understanding Operating Systems, 7e

Necessary Conditions for Deadlock or Livelock Four conditions required for a locked system Mutual exclusion: allowing only one process access to dedicated resource Resource holding: not releasing the resource; waiting for other job to retreat No preemption: lack of temporary reallocation of resources Circular wait: each process waiting for another to voluntarily release so at least one can continue All conditions required for deadlock Understanding Operating Systems, 7e

Necessary Conditions for Deadlock or Livelock (cont'd.) Resolving deadlock: remove one of the conditions All four conditions prevented simultaneously ► deadlock prevented Difficult to implement Understanding Operating Systems, 7e

Strategies for Handling Deadlocks Prevention Prevent occurrence of one condition Mutual exclusion, resource holding, no preemption, circular wait Avoidance Avoid deadlock if it becomes probable Detection Detect deadlock when it occurs Recovery Resume system normalcy quickly and gracefully Understanding Operating Systems, 7e

Starvation Job execution prevented Example Starvation avoidance Waiting for resources that never become available Results from conservative resource allocation Example Dining Philosophers Problem (Dijkstra, 1968) Starvation avoidance Implement algorithm tracking how long each job has been waiting for resources (aging) Starvation detected: block new jobs until starving jobs satisfied Understanding Operating Systems, 7e

Starvation (cont'd.) Understanding Operating Systems, 7e (figure 5.14) Each philosopher must have both forks to begin eating, the one on the right and the one on the left. Unless the resources, the forks, are allocated fairly, some philosophers may starve. © Cengage Learning 2014 Understanding Operating Systems, 7e

Conclusion Operating systems Four methods for dealing with deadlocks Must dynamically allocate resources while avoiding deadlock and starvation Four methods for dealing with deadlocks Prevention, avoidance, detection, and recovery Prevention Remove simultaneous occurrence of one or more conditions: system will become deadlock-free Prevention algorithms Complex algorithms and high execution overhead Understanding Operating Systems, 7e

Conclusion (cont'd.) Avoidance When there is no prevention support: Clearly identify safe and unsafe states Keep reserve resources to guarantee job completion Disadvantage System not fully utilized When there is no prevention support: System must detect and recover from deadlocks Detection relies on selection of victim Understanding Operating Systems, 7e

Understanding Operating Systems Seventh Edition Chapter 6 Concurrent Processes