The document discusses process and thread scheduling in operating systems. It covers the goals of scheduling algorithms which include maximizing CPU utilization and minimizing wait times. It describes common scheduling algorithms like first-come first-served (FCFS), shortest job first (SJF), round-robin, and priority scheduling. The scheduler determines which process or thread runs next using these algorithms to meet objectives like throughput, response time, and meeting deadlines.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
20 views30 pages
Platform Technologies
The document discusses process and thread scheduling in operating systems. It covers the goals of scheduling algorithms which include maximizing CPU utilization and minimizing wait times. It describes common scheduling algorithms like first-come first-served (FCFS), shortest job first (SJF), round-robin, and priority scheduling. The scheduler determines which process or thread runs next using these algorithms to meet objectives like throughput, response time, and meeting deadlines.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 30
Scheduling
Platform Technologies
Based on Based on Tanenbaum, Modern Operating Systems
1 Who gets the CPU?
Based on Tanenbaum, Modern Operating Systems 3 e 2
Process Behaviour
a) CPU-bound processes spend most of their time computing
b) I/O bound processes spend most of their time waiting for I/O
Based on Tanenbaum, Modern Operating Systems 3 e 3
Multiprogramming • Overlapping I/O and CPU activities • To increase CPU utilization and job throughput • Previously covered the mechanisms of • Context switching • Process queues and process states • But… • which process (thread) to run, for how long, etc. – scheduling
Based on Tanenbaum, Modern Operating Systems 3 e 4
Scheduling • Choosing which process to run next, when two or more of them are simultaneously in the ready state • Deciding which process should occupy the resource (CPU, disk, etc.) • Done by scheduler using the scheduling algorithm • Many of the same issues that apply to process scheduling also apply to thread scheduling, although some are different. • Jobs - schedulable entities (processes, threads)
Based on Tanenbaum, Modern Operating Systems 3 e 5
When to schedule? • when a job exits • when a job blocks on I/O • when time slice expired • a hardware clock provides periodic interrupts • when a new job is created • whether to run the parent or the child • when an I/O interrupt occurs • from an I/O device that has now completed its work for a waiting job
Based on Tanenbaum, Modern Operating Systems 3 e 6
Performance Criteria • Throughput • number of jobs completed in unit time • Turnaround time (elapse time) • Amount of time to execute a particular process from the time it entered • Waiting time • Amount of time process has been waiting in ready queue • Meeting deadlines • Avoid bad consequences
Based on Tanenbaum, Modern Operating Systems 3 e 7
Scheduling Objectives • Fair • Encourage good behavior • Everyone is happy • Good boy/girl • Priority • Support heavy load • Some are more important • Degrade gracefully • Efficiency • Adapt to different environment • Make best use of equipment • Interactive, real-time, multi-media
Based on Tanenbaum, Modern Operating Systems 3 e 8
Categories of Scheduling Algorithms 1. Batch • Periodic tasks – payroll, bills, interest calculation (at banks) • No users impatiently waiting • Possible to run for long time periods for each process without switching 2. Interactive • For environments with interactive users – personal computing, servers • One process cannot be hogging the CPU and denying service to the others 3. Real-time • Only programs that are intended to further the application at hand • Processes may not run for long and usually do their work and block quickly • So, it’s okay to let them finish
Based on Tanenbaum, Modern Operating Systems 3 e 9
Preemptive vs. Non-preemptive • Non-preemptive scheduling • The running process keeps the CPU until it voluntarily gives up the CPU • Preemptive scheduling • The running process can be interrupted and must release the CPU
Based on Tanenbaum, Modern Operating Systems 3 e 10
Scheduling Algorithm Goals
Based on Tanenbaum, Modern Operating Systems 3 e 11
Scheduling Algorithms • Batch Systems • First-Come, First-Served (FCFS) • Short Job First (SJF) • Interactive Systems • Round-Robin Scheduling • Priority Scheduling • Multi-Queue & Multi-Level Feedback • Real-time Systems • Earliest Deadline First Scheduling
Based on Tanenbaum, Modern Operating Systems 3 e 12
First-Come, First-Served (FCFS) • “Real-world” scheduling of people in lines (e.g., supermarket) • A single queue of ready jobs • Jobs are scheduled in order of arrival to ready queue • Typically non-preemptive (no context switching at market) • Jobs treated equally, no starvation. • When the running process blocks, the first process on the queue is run next. • When a blocked process becomes ready, like a newly arrived job, it is put on the end of the queue, behind all waiting processes. Based on Tanenbaum, Modern Operating Systems 3 e 13 First-Come, First-Served – Example
Based on Tanenbaum, Modern Operating Systems 3 e 14
First-Come, First-Served – Problems • Average waiting time can be large • If small jobs wait behind long ones (high turnaround time) • Non-preemptive • You’re stuck behind someone with a cart, when you only have two items • Solution? • Express lane (10 items or less)
Based on Tanenbaum, Modern Operating Systems 3 e 15
Shortest Job First (SJF) • Choose the job with the smallest expected duration first • Person with smallest number of items to buy • Requirement • the job duration needs to be known in advance • Used in Batch Systems • Optimal for Average Waiting Time if all jobs are available simultaneously
Based on Tanenbaum, Modern Operating Systems 3 e 16
Shortest Job First – Example
Based on Tanenbaum, Modern Operating Systems 3 e 17
FCFS vs. SJF
Based on Tanenbaum, Modern Operating Systems 3 e 18
Shortest Job First – Problems • Starvation • a job is waiting forever • All jobs must be available at start • Suited for batch systems
Based on Tanenbaum, Modern Operating Systems 3 e 19
Scheduling Algorithms • Batch Systems • First-Come, First-Served (FCFS) • Short Job First (SJF) • Interactive Systems • Round-Robin Scheduling • Priority Scheduling • Multi-Queue & Multi-Level Feedback • Real-time Systems • Earliest Deadline First Scheduling
Based on Tanenbaum, Modern Operating Systems 3 e 20
Round-Robin Scheduling • One of the oldest, simplest, most commonly used scheduling algorithm • Select process/thread from ready queue in a round-robin fashion (take turns)
Based on Tanenbaum, Modern Operating Systems 3 e 21
Round-Robin Scheduling – Example
Based on Tanenbaum, Modern Operating Systems 3 e 22
Round-Robin Scheduling – Problems • Time slice too large • FIFO behavior • Poor response to short interactive requests • Time slice too small • Too many context switches (overheads) • Inefficient CPU utilization • A quantum around 20–50 msec is often a reasonable compromise.
Based on Tanenbaum, Modern Operating Systems 3 e 23
Priority Scheduling • Not all processes are equally important • Need to consider external factors • Email checking less priority than displaying video
Based on Tanenbaum, Modern Operating Systems 3 e 24
Multiple-level feedback queues (MLFQ) • Scheduling algorithms can be combined • Have multiple queues • Use a different algorithm among queues • Move processes among queues • Multiple queues representing different job types • Interactive, CPU-bound, batch, etc. • Queues have priorities • Jobs can move among queues based upon execution history
Based on Tanenbaum, Modern Operating Systems 3 e 25
Scheduling Algorithms • Batch Systems • First-Come, First-Served (FCFS) • Short Job First (SJF) • Interactive Systems • Round-Robin Scheduling • Priority Scheduling • Multi-Queue & Multi-Level Feedback • Real-time Systems • Earliest Deadline First Scheduling
Based on Tanenbaum, Modern Operating Systems 3 e 26
Earliest Deadline First (EDF) • Each job has an arrival time and a deadline to finish • Assignments, exams* • Always pick the job with the earliest deadline to run
Based on Tanenbaum, Modern Operating Systems 3 e 27
Thread Scheduling • Two levels of threads • User-level threads • Kernel-level threads • User-level threads • Kernel picks the process • Scheduler inside process picks thread • Kernel-level threads • Kernel picks a particular thread to run • Requires a full context switch
Based on Tanenbaum, Modern Operating Systems 3 e 28
Thread Scheduling
Based on Tanenbaum, Modern Operating Systems 3 e 29
Scheduling Summary • Scheduler is the module that gets invoked when a context switch needs to happen • Scheduling algorithm determines which process runs and where processes are placed on queues • Scheduling algorithms have many goals • Utilization, throughput, wait time, response time, etc. • Various algorithms to meet these goals • FCFS/FIFO, SJF, RR, Priority • Can combine algorithms • Multiple-level feedback queues
Based on Tanenbaum, Modern Operating Systems 3 e 30