CSE 120. Summer, Inter-Process Communication (IPC) Day 3. Inter-Process Communication (IPC) Scheduling Deadlock. Instructor: Neil Rhodes

Similar documents
CSC Operating Systems Spring Lecture - XII Midterm Review. Tevfik Ko!ar. Louisiana State University. March 4 th, 2008.

Operating Systems: Quiz2 December 15, Class: No. Name:

UNIT:2. Process Management

CSE 120. Fall Lecture 8: Scheduling and Deadlock. Keith Marzullo

Scheduling of processes

Operating Systems. Scheduling

Review. Preview. Three Level Scheduler. Scheduler. Process behavior. Effective CPU Scheduler is essential. Process Scheduling

Operating Systems. Lecture Process Scheduling. Golestan University. Hossein Momeni

CSE 120 Principles of Operating Systems

Lecture 2 Process Management

CS 571 Operating Systems. Midterm Review. Angelos Stavrou, George Mason University

Scheduling. The Basics

What is the Race Condition? And what is its solution? What is a critical section? And what is the critical section problem?

Maximum CPU utilization obtained with multiprogramming. CPU I/O Burst Cycle Process execution consists of a cycle of CPU execution and I/O wait

Topic 4 Scheduling. The objective of multi-programming is to have some process running at all times, to maximize CPU utilization.

The Slide does not contain all the information and cannot be treated as a study material for Operating System. Please refer the text book for exams.

Preview. Process Scheduler. Process Scheduling Algorithms for Batch System. Process Scheduling Algorithms for Interactive System

CS 153 Design of Operating Systems Winter 2016

Chapter 5: CPU Scheduling

The Deadlock Problem. A set of blocked processes each holding a resource and waiting to acquire a resource held by another process in the set.

Lecture 9: Midterm Review

CPU Scheduling. CSE 2431: Introduction to Operating Systems Reading: Chapter 6, [OSC] (except Sections )

Lecture Topics. Announcements. Today: Uniprocessor Scheduling (Stallings, chapter ) Next: Advanced Scheduling (Stallings, chapter

Tasks. Task Implementation and management

OPERATING SYSTEMS. UNIT II Sections A, B & D. An operating system executes a variety of programs:

Bridge Crossing Example

OPERATING SYSTEMS. Deadlocks

Course Syllabus. Operating Systems

General Objectives: To understand the process management in operating system. Specific Objectives: At the end of the unit you should be able to:

Last Class: Processes

CSE120 Principles of Operating Systems. Prof Yuanyuan (YY) Zhou Scheduling

OPERATING SYSTEMS CS3502 Spring Processor Scheduling. Chapter 5

Operating Systems ECE344. Ding Yuan

Chapter 8: Deadlocks. The Deadlock Problem

The Deadlock Problem. Chapter 8: Deadlocks. Bridge Crossing Example. System Model. Deadlock Characterization. Resource-Allocation Graph

1.1 CPU I/O Burst Cycle

Announcements. Program #1. Program #0. Reading. Is due at 9:00 AM on Thursday. Re-grade requests are due by Monday at 11:59:59 PM.

Uniprocessor Scheduling. Aim of Scheduling

Uniprocessor Scheduling. Aim of Scheduling. Types of Scheduling. Long-Term Scheduling. Chapter 9. Response time Throughput Processor efficiency

! What is a deadlock? ! What causes a deadlock? ! How do you deal with (potential) deadlocks? Maria Hybinette, UGA

Deadlocks. Minsoo Ryu. Real-Time Computing and Communications Lab. Hanyang University.

CSE 306/506 Operating Systems Deadlock. YoungMin Kwon

CPU Scheduling Algorithms

Deadlocks. Dr. Yingwu Zhu

MODERN OPERATING SYSTEMS. Third Edition ANDREW S. TANENBAUM. Chapter 6 Deadlocks

The Deadlock Problem (1)

Deadlocks. Mehdi Kargahi School of ECE University of Tehran Spring 2008

Process Management. Deadlock. Process Synchronization. Management Management. Starvation

Last Class: Monitors. Real-world Examples

!! What is a deadlock? !! What causes a deadlock? !! How do you deal with (potential) deadlocks? Maria Hybinette, UGA

CPU Scheduling. The scheduling problem: When do we make decision? - Have K jobs ready to run - Have N 1 CPUs - Which jobs to assign to which CPU(s)

Announcements. Program #1. Reading. Due 2/15 at 5:00 pm. Finish scheduling Process Synchronization: Chapter 6 (8 th Ed) or Chapter 7 (6 th Ed)

CSCE Operating Systems Scheduling. Qiang Zeng, Ph.D. Fall 2018

Deadlock and Starvation

Chapter 8: Deadlocks. Bridge Crossing Example. The Deadlock Problem

Scheduling Bits & Pieces

Chapter 7: Deadlocks

Readings and References. Deadlock. Deadlock. Simple Traffic Gridlock Example. Reading. CSE Computer Systems November 30, 2001.

COMP 300E Operating Systems Fall Semester 2011 Midterm Examination SAMPLE. Name: Student ID:

CMSC 412. Announcements

Last Class: Synchronization Problems. Need to hold multiple resources to perform task. CS377: Operating Systems. Real-world Examples

Chapter 6: CPU Scheduling

Uniprocessor Scheduling. Chapter 9

Contents. Chapter 8 Deadlocks

CSE 153 Design of Operating Systems

System Model. Types of resources Reusable Resources Consumable Resources

Process P holds resource R. Process P is waiting for resource R. P Process P holds T and requests R. R Process Q holds R and requests T

Deadlocks. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Chapter 9 Uniprocessor Scheduling

Chapter 7: Deadlocks. Operating System Concepts 9 th Edition

CPU Scheduling. The scheduling problem: When do we make decision? - Have K jobs ready to run - Have N 1 CPUs - Which jobs to assign to which CPU(s)

Operating System: Chap7 Deadlocks. National Tsing-Hua University 2016, Fall Semester

Chapter 8: Deadlocks

Chapter 8: Deadlocks. The Deadlock Problem. System Model. Bridge Crossing Example. Resource-Allocation Graph. Deadlock Characterization

OPERATING SYSTEMS. Prescribed Text Book. Operating System Principles, Seventh Edition. Abraham Silberschatz, Peter Baer Galvin and Greg Gagne

Chapter 6. Deadlocks

Ch 4 : CPU scheduling

Chapter 8: Deadlocks. The Deadlock Problem

Interactive Scheduling

Two Level Scheduling. Interactive Scheduling. Our Earlier Example. Round Robin Scheduling. Round Robin Schedule. Round Robin Schedule

Module 7: Deadlocks. The Deadlock Problem. Bridge Crossing Example. System Model

Processes-Process Concept:

Chapter 6 Concurrency: Deadlock and Starvation

Operating Systems. Deadlocks

Chapter 7: Deadlocks. Operating System Concepts 8th Edition, modified by Stewart Weiss

Midterm Exam #2 Solutions October 25, 2016 CS162 Operating Systems

8: Scheduling. Scheduling. Mark Handley

Techno India Batanagar Department of Computer Science & Engineering. Model Questions. Multiple Choice Questions:

Deadlock. Readings and References. Simple Traffic Gridlock Example. Deadlock. Reading. Other References. CSE 410, Spring 2006 Computer Systems

CPU Scheduling. Schedulers. CPSC 313: Intro to Computer Systems. Intro to Scheduling. Schedulers in the OS

The Deadlock Problem

Chapter 7: Deadlocks

CSE Opera+ng System Principles

Scheduling. Today. Next Time Process interaction & communication

Deadlocks. Deadlock in Resource Sharing Environment. CIT 595 Spring Recap Example. Representing Deadlock

Uniprocessor Scheduling

Chapter 7: Deadlocks

Last Class: CPU Scheduling! Adjusting Priorities in MLFQ!

CS370 Operating Systems

Deadlocks. Deadlock Overview

Transcription:

CSE 120 Summer, 2005 Inter-Process Communication (IPC) Day 3 Inter-Process Communication (IPC) Scheduling Deadlock Instructor: Neil Rhodes Inter-Process Communication Cooperating processes must communicate Need way to Transfer information Synchronize Different types of IPC Shared Memory Synchronization carried out via semaphores or monitors Message passing Remote Procedure Call (RPC) Message Passing One process sends a message, another receives it Variable-size / fixed-size message Direct or indirect communication Directly specify other process - Symmetric: Send(P, message) / Receive(Q, &message) - Asymmetric: Send(P, message) / Receive(&processID, &message) Indirect: use mailbox or port - send(mboxa, message) / Receive(MboxA, &message) Synchronous or asynchronous Blocking send Nonblocking send Blocking receive Nonblocking receive Combo of blocking send and blocking receive yields a rendezvous Buffering: zero, bounded, or unbounded Zero: sender blocks until receiver receives message Bounded: If the buffer is full, sender blocks Unbounded: sender never blocks 3 4

Remote Procedure Call (RPC) Make a procedure call that invokes procedure in remote process Could be process on the same machine, or process across a network How it works: Local stub marshals parameters May need to convert to machine-independent format Sends message with procedure ID and parameters Waits for receipt of message with return result Scheduling Remote Method Invocation (RMI) Used in Java as a way to cause a method to be executed on a remote object Corba (Common Object Request Broker Architecture) Language- and platform-neutral way to execute methods on objects 5 Scheduler Scheduling Part of the operating system that decides which ready process to run next Scheduling Algorithm Algorithm the scheduler uses Types of Processes I/O-bound CPU-bound Throughput Scheduling Goals Number of jobs per time period (or work/time period) Fairness Some jobs aren t arbitrarily treated differently from others Response Time Time till some output Turnaround time Time until process complete Predictability Low variance Meeting deadlines Multimedia, for example CPU utilization Don t waste if critical path Proportionality Simple things are quicker than complicated things 7 8

First-Come First-Served No preemption Easy to understand Low throughput and CPU utilization given I/O-bound processes Shortest Process Next Look at CPU burst (not total CPU until completed) Let job run non-preemptively Predict based on history of CPU burst (Ti = time used for ith period. Si = estimate of ith period) Straight average: Sn+1=1/nTn + (n-1)/nsn Exponential average: Sn+1=Tn + (1-)Sn Reduces average turnaround time Shortest Remaining Time Based on estimate of total time (given by user or estimated from history)- time spent so far Preemptive at time of arrival Highest Response Ratio Next Response ratio = (waiting time + total time)/waiting time Chose job with highest response ratio Round-robin scheduling Give each job a timeslice (quantum). Preempt if still running Put job at end of ready queue and run next job in ready queue Quantum should be large relative to context-switch time 9 10 Four processes Comparison A: arrives at time 0, CPU time 3 B: arrives at time 2, CPU time: 6 C: arrives at time 4, CPU time: 5 D: arrives at time 6: CPU time: 4 FCFS RR (q=1) RR (q=4) SPN SRT HRRN Priority Scheduling Priority associated with each process High priority job runs before any lower priority jobs Starvation is a problem Solution: Aging (slowly increase priority of waiting processes) Multilevel Queue Scheduling Distinguish between different classes of processes Student/Instructor/interactive/system batch/interactive Queues can have different scheduling algorithms Need scheduling between queues Multilevel Feedback-Queue Scheduling Different queues, processes move from queue to queue based on their history For example: Queue 1: 1 quantum. If a process uses its entire quantum, it moves to next Queue Queue 2: 2 quanta. if a process uses its entire quantum, it moves to next Queue Queue 3: 4 quanta. 0 5 10 15 20 11 12

Fair-share scheduling Divide user community into a set of fair-share groups. Allocate a fraction of the processor resource to each group Each group gets its fair-share of the CPU time Priority of a process depends on: How much CPU time its group has had recently How much CPU time it itself has had recently Base priority of the process Example 3 process: A, B, C. A is in group 1, B&C are in group 2. Assume fair-share is group 1: 50%, group 2: 50% Possible scheduling sequence: - A B A C A B A C A B A C Lottery Scheduling Give processes lottery tickets Randomly choose a ticket: whoever has ticket gets to run Some processes can have more tickets than others If a process holds 20% of the tickets, in the long run, it ll get 20% of the CPU A process can give tickets to another process Example: When a client makes a blocking request to a server, it give the server its tickets. Server doesn t normally need any tickets If a process doesn t use its entire quantum, give a compensation ticket that increases its tickets by a certain amount until next time it runs For example, if process A and process B each have 400 tickets, but A uses its entire quantum and B uses 1/5, then A will get 5 times as much time as B When B uses only 1/5 of a quantum, give compensation ticket worth 1600. Next lottery, B has 2000, A has 400. B is 5 times more likely to win the lottery 13 14 Image three levels of priority High Medium Low Priority Inversion We want high priority processes to run before any medium or low L (a low priority process) holds a mutex. H (a high priority process) blocks trying to obtain the mutex M (a medium priority process) runs since: H is blocked L is of lower priority Meanwhile, H can t run because it s waiting for L Deadlock Solution: Priority Donation: While L holds a resource, it gets (temporarily) priority of higher processes waiting for it. 15

Deadlock A chain of processes exist that are blocked waiting on one another Each process has requested a resource that another process is holding Process A: Request(resourceA) Request(resourceB) Release(resourceB) Release(resourceA) Process B: Request(resourceB) Request(resourceC) Release(resourceC) Release(resourceB) Process C: Request(resourceC) Request(resourceD) Release(resourceD) Release(resourceC) Process D: Request(resourceD) Request(resourceA) Release(resourceA) Release(resourceD) Necessary Conditions for Deadlock Can t have deadlock unless we have all four conditions: Mutual Exclusion: If process A requests a resource that process B is using, process A is blocked. Hold and wait: At least one process must be holding a resource and waiting for another (blocked). No preemption: A process can t be forced to release a process; it must do so voluntarily after it has finished its task Circular wait: A set of resources {P0, P1,, Pn} of waiting processes must exist where P0 is waiting for a resource held by P1, P1 waiting for a resource held by P2, Pn waiting for a resource held by P0. 17 18 Resource-Allocation Graph Arrow from resource instance to process if process has resource allocated Arrow from process to resource if process has requested resource Resource A Ways to Deal with Deadlock Deadlock Prevention Change rules so deadlock can t happen Deadlock Avoidance Check each allocation to see whether that could lead to a future deadlock situation Deadlock Detection Detect Recover Process 1 Process 2 Resource B 19 20

Deadlock Prevention Ensure no deadlocks by removing one of the 4 necessary conditions Mutual Exclusion Some resources are sharable: read-only files, for example. Others are intrinsically non-sharable (CD-burner, for example) Can make some non-sharable resources sharable - Spooler for printer, for example Can t remove this condition for all resources, though Hold and Wait Require each process to allocate all resources before it begins execution Request resources in a group: can only request if not holding any No Preemption If process requests a resource but must wait, it gives up all its existing resources. These are added to list of resources it is waiting for Or, if process is waiting holding a resource, resource may be preempted if needed by another process. First process wakes up only when all resources it needs are available Problem: some resources state can t be maintained when taken away and then given back: in the middle of writing to a tape, for example. Circular Wait Impose an ordering on the resources Processes must request resources in increasing order Deadlock Avoidance Process provides additional information about their future resource usage for example, maximum number of resources of each type that it may need System is kept in a safe state Unsafe states can lead to deadlock If the state is safe now, based on the knowledge of possible future requests, it can be kept safe deadlock unsafe safe 21 22 Safe/Unsafe states 2 Processes each acquiring two resources B Bankers Algorithm Imagine a bank with: n customers each with a line of credit A certain amount of money on hand Want to make sure that if we lend any money to a customer We ll be able to satisfy all future requests up to the line of credit. Printer Plotter Don t want to be in a situation where we ve got no money and all customers with current loans out want more money Leave enough money-on-hand to satisfy all needs of at least one customer (if their payback is enough to satisfy one more customer, etc.) Printer Plotter A 23 24

Deadlock Avoidance Don t grant resource request if it takes system to an unsafe state Even if the resource is currently available Banker s Algorithm Let n = number of processes, m = number of resource types Define V[m]: # of resources of a particular type currently available Define D[n,m]: Maximum demand of each process (specified when process begins) Define A[n, m]: current allocation of each process/type pair Define N[n, m]: How much more a process may need (=M-A) Assumptions: Bankers Algorithm Maximum resource requirements for a process stated in advance Processes must be independent (A can t be waiting on B for anything other than a resource it has) Fixed number of resources A process can t exit while keeping its resources When request is made: Assume temporarily that the request is granted Update state and determine whether it is still safe If not, restore the state and don t satisfy the request Determining whether a state is safe Recursively: Can some process maximum demand be satisfied by their current allocation and the available resources? If so, that process could finish, and return its resources. Update state as if resources were returned and continue If any processes still remaining, state is not safe 25 26 Detection Deadlock Detection Recursively: Can some process current request be satisfied by the available resources? If so, that process could finish, and return its resources. Mark it, update available resources, and continue Any processes that remain unmarked are deadlocked. Must run algorithm to detect deadlock. How often? Recovery - When system is slow - Once per time period - Every time a resource allocation would block? Process Termination Abort all deadlocked processes Abort one process at a time until the deadlock cycle is eliminated Resource Preemption Take away already allocated resources from some process - Rollback that process to known good state? 27