Slide 6-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 Threads and Scheduling 6.

Slides:



Advertisements
Similar presentations
Scheduling Criteria CPU utilization – keep the CPU as busy as possible (from 0% to 100%) Throughput – # of processes that complete their execution per.
Advertisements

Scheduling CSCI 3753 Operating Systems Spring 2005 Prof. Rick Han.
Operating Systems Process Scheduling (Ch 3.2, )
CS4315A. Berrached:CMS:UHD1 CPU Scheduling Chapter 7.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts Essentials – 2 nd Edition Chapter 6a: CPU Scheduling.
A. Frank - P. Weisberg Operating Systems Advanced CPU Scheduling.
 Basic Concepts  Scheduling Criteria  Scheduling Algorithms.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 5: CPU Scheduling.
Operating Systems Chapter 6
Operating Systems CPU Scheduling. Agenda for Today What is Scheduler and its types Short-term scheduler Dispatcher Reasons for invoking scheduler Optimization.
Day 25 Uniprocessor scheduling. Algorithm: Selection function Selection function – which process among ready processes to select. w – time spent in system,
Chapter 3: CPU Scheduling
CS 311 – Lecture 23 Outline Kernel – Process subsystem Process scheduling Scheduling algorithms User mode and kernel mode Lecture 231CS Operating.
Scheduling in Batch Systems
Introduction to Operating Systems – Windows process and thread management In this lecture we will cover Threads and processes in Windows Thread priority.
1 Thursday, June 15, 2006 Confucius says: He who play in root, eventually kill tree.
3.5 Interprocess Communication
1 When to Switch Processes 3 triggers –System call, Interrupt and Trap System call –when a user program invokes a system call. e.g., a system call that.
Signals, Synchronization CSCI 3753 Operating Systems Spring 2005 Prof. Rick Han.
Job scheduling Queue discipline.
Operating Systems Process Scheduling (Ch 4.2, )
Slide 6-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 Threads and Scheduling 6.
1 Lecture 10: Uniprocessor Scheduling. 2 CPU Scheduling n The problem: scheduling the usage of a single processor among all the existing processes in.
1Chapter 05, Fall 2008 CPU Scheduling The CPU scheduler (sometimes called the dispatcher or short-term scheduler): Selects a process from the ready queue.
UNIX Signals Bach 7.2 Operating Systems Course The Hebrew University Spring 2010.
Chapter 5: CPU Scheduling (Continuation). 5.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 2, 2005 Determining Length.
CPU Scheduling Chapter 6 Chapter 6.
Chapter 6: CPU Scheduling
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-3 CPU Scheduling Department of Computer Science and Software Engineering.
Copyright © 2006 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill Technology Education Lecture 5 Operating Systems.
Chapter 6 CPU SCHEDULING.
Operating System Examples - Scheduling
Scheduling. Alternating Sequence of CPU And I/O Bursts.
Uniprocessor Scheduling Chapter 9. Aim of Scheduling To improve: Response time: time it takes a system to react to a given input Turnaround Time (TAT)
Scheduling Example 3 (1) Assume: FIFO Job Scheduling 100 K Main Memory Processor Sharing Process Scheduling (Cont…)
1 Our focus  scheduling a single CPU among all the processes in the system  Key Criteria: Maximize CPU utilization Maximize throughput Minimize waiting.
CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms Thread Scheduling Multiple-Processor Scheduling Operating Systems Examples Algorithm.
Lecture 7: Scheduling preemptive/non-preemptive scheduler CPU bursts
Uniprocessor Scheduling
Uniprocessor Scheduling Chapter 9. Processor Scheduling Processor scheduling determines the assignment of processes to be executed by the processor over.
Chapter 5: Process Scheduling. 5.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Basic Concepts Maximum CPU utilization can be obtained.
1 Signals (continued) CS 241 April 9, 2012 University of Illinois.
Process Program (Passive Entity) is a sequence of instructions, written to perform a specified task on a computer. A computer requires programs to function,
UNIX Signals * POSIX-Defined Signals * Signaling Processes * Signal Mask * sigaction * kill and sigaction * alarm * Interval Timers * POSIX.1b Timers *
Operating Systems Recitation 4, April th, 2002 Signals.
Signals. Introduction r A signal is a mechanism for notifying a process that an event has occurred. m When a signal is sent to a process is normal execution.
Lecture Topics: 11/15 CPU scheduling: –Scheduling goals and algorithms.
1 CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms Multiple-Processor Scheduling Real-Time Scheduling.
1 Lecture 19: Unix signals and Terminal management n what is a signal n signal handling u kernel u user n signal generation n signal example usage n terminal.
Copyright ©: Nahrstedt, Angrave, Abdelzaher, Caccamo1 Signals.
1 Uniprocessor Scheduling Chapter 3. 2 Alternating Sequence of CPU And I/O Bursts.
Lecture 4 CPU scheduling. Basic Concepts Single Process  one process at a time Maximum CPU utilization obtained with multiprogramming CPU idle :waiting.
CPU scheduling.  Single Process  one process at a time  Maximum CPU utilization obtained with multiprogramming  CPU idle :waiting time is wasted 2.
Lecturer 5: Process Scheduling Process Scheduling  Criteria & Objectives Types of Scheduling  Long term  Medium term  Short term CPU Scheduling Algorithms.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 5: CPU Scheduling.
Advanced Operating Systems CS6025 Spring 2016 Processes and Threads (Chapter 2)
Chapter 4: Threads.
Chapter 6: CPU Scheduling
Chapter 5a: CPU Scheduling
Chapter 2 Scheduling.
Chapter 5: CPU Scheduling
Exceptional Control Flow Part II
Process management Information maintained by OS for process management
CPU Scheduling Basic Concepts Scheduling Criteria
Chapter 6: CPU Scheduling
Chapter 5: CPU Scheduling
Operating System Concepts
Exceptional Control Flow
Process Scheduling Decide which process should run and for how long
Outline Announcement Process Scheduling– continued
Presentation transcript:

Slide 6-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 Threads and Scheduling 6

Slide 6-2 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 Announcements Program Assignment #1 due Tuesday Feb. 15 at 11 am –TA will explain parts b-d in recitation Read chapters 7 and 8

Slide 6-3 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 Round Robin Scheduling The ready queue is treated as a circular queue, and the CPU scheduler rotates among the processes in the ready queue, giving each a time slice, after which it is preempted by a timer interrupt and the next process is started –useful for time sharing multitasking systems - most widely used scheduling algorithm –combines FCFS and preemption simple and fair, though wait times can be long –Fair: If there are n processes, each process gets 1/n of CPU –Simple: Don’t need to know service times a priori A process can finish before its time slice is up. The scheduler just selects the next process in the queue

Slide 6-4 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 Round Robin Scheduling Suppose we use a time slice of 4 ms, and ignoring context switch overhead Now P1 is time sliced out, and P2 and P3 are allowed to run sooner than FCFS average wait time is 5.66 ms ProcessCPU Service Time (ms) P124 P23 P33 P P2 P P1

Slide 6-5 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 Round Robin Scheduling Weighted Round Robin - each process is given some number of time slices, not just one per round this is a way to provide preferences or priorities even with preemptive time slicing

Slide 6-6 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 Multi-level Queue Scheduling Partitions ready queue into several queues –different processes have different needs, e.g. foreground and background –so don’t apply the same scheduling policy to every process, e.g. foreground gets RR, background gets FCFS Queues can be organized by priority, or each given a percentage of CPU, or a hybrid combination

Slide 6-7 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 Multi-level Feedback Queues Allows processes to move between queues Criteria for movement could depend upon: –age of a process: old processes move to higher priority queues –behavior of a process: could be CPU-bound processes move down the hierarchy of queues, allowing interactive and I/O-bound processes to move up give a time slice to each queue, with smaller time slices higher up if a process doesn’t finish by its time slice, it is moved down to the next lowest queue

Slide 6-8 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 Signals Allows one process to interrupt another process A message that notifies a process that some event has occurred 30 types of signals on Linux systems Each signal corresponds to some kind of system event

Slide 6-9 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 Signals Prior to signals, low-level hardware exceptions are processed by kernel’s exception handlers, and are not normally visible to user processes –compare to: software “interrupts” - traps/system calls, process calls OS hardware interrupts - OS handles the interrupt, can resume a blocked process after I/O is complete Signals expose occurrences of such low-level exceptions to user processes If a process attempts to divide by zero, kernel sends a SIGFPE signal (number 8) If a process makes an illegal memory reference, the kernel sends it a SIGSEGV signal (number 11) If you type a ctrl-C, this sends a SIGINT to foreground process A process can terminate another process by sending it a SIGKILL signal (#9)

Slide 6-10 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 Signals Kernel sends a signal to a destination process by updating some state in the context of destination process A destination process receives a signal when it is forced by the kernel to react in some way to the delivery of the signal: –ignore signal –terminate –catch the signal by executing a user-level function called the signal handler

Slide 6-11 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 Signals A signal that has been sent but not yet received is called a pending signal At any point in time, there can be at most one pending signal of a particular type a process can selectively block the receipt of certain signals when a signal is blocked, it can be delivered, but the resulting pending signal will not be received until the process unblocks the signal A pending signal is received at most once For each process, the kernel maintains the set of pending signals in the pending bit vector, and the set of blocked signals in the blocked bit vector

Slide 6-12 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 Signals NumberNameEvent 2SIGINTInterrupt from keyboard 11SIGSEGVinvalid memory ref 14SIGALRMTimer signal from alarm fn 29SIGIOI/O now possible on descriptor

Slide 6-13 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 Signals Default action is to terminate a process Sending signals with kill function –kill -9 PID A process can send SIGALRM signals to itself by calling the alarm function –alarm(T seconds) arranges for kernel to send a SIGALRM signal to calling process in T seconds –see code example #include uses signal function to install a signal handler function that is called asynchronously, interrupting the infinite while loop in main, whenever the process receives a SIGALRM signal When handler returns, control passes back to main, which picks up where it was interrupted by the arrival of the signal

Slide 6-14 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 Signals Receiving signals: –when a kernel is returning from some exception handler, it checks to see if there are any pending signals for a process before passing control to process –default action is typically termination –signal(signum, handler) function used to change the action associated with a signal if handler is SIG_IGN, then signals of type signum are ignored if handler is SIG_DFL, then revert to default action otherwise handler is user-defined function call the signal handler. This installs or registers the signal handler. –Invocation of the signal handler is called catching the signal –Execution of signal handler is called handling the signal

Slide 6-15 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 Signals When a process catches a signal of type k, the handler installed for signal k is invoked with a single integer argument set to k This argument allows the same handler function to catch different types of signals When handler executes its return statement (finishes), control usually passes back to the instruction where the process was interrupted

Slide 6-16 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 Signals Handling multiple signals –choose to handle the lower number signals first –pending signals are blocked, e.g. if a 2 nd SIGINT is received while handling 1 st SIGINT, the 2 nd SIGINT becomes pending and won’t be received until after the handler returns –pending signals are not queued there can be at most one pending signal of type k –system calls can be interrupted slow system calls that are interrupted may not resume in some systems, and may return immediately with an error

Slide 6-17 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 Signals Portable signal handling: sigaction() is a standard POSIX API for signal handling –allows users on Posix-compliant systems such as Linux and Solaris to specify the signal-handling semantics they want, e.g. whether sys call is aborted or restarted sigaction(signum, struct sigaction*act, struct sigaction *oldact) each struct sigaction can define a handler, e.g. action.sa_handler = handler; In part iv of PA #1, use sigaction() to define the handler, e.g. reschedule Also need to set up the timer (use setitimer instead of alarm). A SIGALRM is delivered when timer expires.