Download as pdf or txt
Download as pdf or txt
You are on page 1of 21

CHAPTER 3

SCHEDULING
Who gets the CPU?
PROCESS BEHAVIOR
SCHEDULING
Processes alternate bursts of computing with I/O requests
CPU burst is the amount of time the process uses the
processor before it is no longer ready

The CPU runs for a while without stopping, then a system call is
made to read from a file or write to a file.

When the system call completes, the CPU computes again until it
needs more data or has to write more data
PROCESS BEHAVIOR
SCHEDULING

Bursts of CPU usage alternate with periods of waiting for I/O.


(a) A CPU-bound process. (b) An I/O-bound process.
PROCESS BEHAVIOR
SCHEDULING
CPU-BOUND I/O BOUND

CPU-bound or compute- I/O-bound processes


bound processes have have short CPU bursts
long CPU bursts and and thus frequent I/O
thus infrequent I/O waits waits
WHEN TO SCHEDULE
SCHEDULING
1. When a new process is created
a decision needs to be made whether to run the parent process or
the child process
2. When a process exits
a process can no longer run (since it no longer exists), some other
process must be chosen from the set of ready processes
3. When a process blocks on I/O
4. When an I/O interrupt occurs
if the interrupt came from an I/O device that has completed its work,
some process that was blocked waiting for the I/O may now be run
WHAT IS SCHEDULING
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)

Done by scheduler using the scheduling algorithm

Many of the same issues that apply to process scheduling also


apply to thread scheduling
SCHEDULING ALGORITHM
SCHEDULING
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 deny service to others
3. Real-time
Processes may not run for long and usually do their work and block
quickly
SCHEDULING ALGORITHM
SCHEDULING GOALS

All systems
Fairness - giving each process a fair share of the CPU
Policy enforcement - seeing that stated policy is carried out
Balance - keeping all parts of the system busy
Batch systems
Throughput - maximize jobs per hour
Turnaround time - minimize time between submission and termination
CPU utilization - keep the CPU busy all the time
Interactive systems
Response time - respond to requests quickly
Proportionality - meet users’ expectations
Real-time systems
Meeting deadlines - avoid losing data
Predictability - avoid quality degradation in multimedia systems
SCHEDULING IN
SCHEDULING BATCH SYSTEMS

1. First-Come, First-Served
Processes are assigned the CPU in the order they request it
A single queue of ready jobs
Jobs are scheduled in order of arrival to ready queue
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
FCFS EXAMPLE
SCHEDULING

31

P1 waiting time: 0 The total time is: 31


P2 waiting time: 24 The average waiting time (AWT):
P3 waiting time: 27
(0+24+27)/3= 17
SCHEDULING IN
SCHEDULING BATCH SYSTEMS

2. Shortest Job First


Choose the job with the smallest expected duration first
Requirement
the job duration needs to be known in advance
Optimal for Average Waiting Time if all jobs are available
simultaneously
SJF EXAMPLE
SCHEDULING

P4 waiting time: 0 The total time is: 24


P1 waiting time: 3 The average waiting time (AWT):
P3 waiting time: 9
P2 waiting time: 16 (0+3+9+16)/4 = 7
FCFS VS. SJF EXAMPLE
SCHEDULING

P1 waiting time: 0
P2 waiting time: 6 The average waiting time (AWT):
P3 waiting time: 14 (0+6+14+21)/4 = 10.25
P4 waiting time: 21
SCHEDULING IN
SCHEDULING INTERACTIVE SYSTEMS

1. Round-Robin Scheduling
One of the oldest, simplest, most commonly used scheduling
algorithm
Select a process from ready queue in a round-robin fashion (take
turns)
Each process is assigned a time interval, called its quantum,
during which it is allowed to run
If the process is still running at the end of the quantum, the
CPU is preempted and given to another process
ROUND ROBIN EXAMPLE
SCHEDULING

P1 waiting time: 0 The average waiting time (AWT):


P2 waiting time: 4 (0+4+6)/3 = 3.33
P3 waiting time: 6
SCHEDULING IN
SCHEDULING INTERACTIVE SYSTEMS

2. Priority Scheduling
Not all processes are equally important
Each process is assigned a priority, and the runnable process with
the highest priority is allowed to run
On a PC with a single owner, there may be multiple processes,
some of them more important than others
For example, a daemon process sending electronic mail in the
background should be assigned a lower priority than a
process displaying a video on the screen in real time
SCHEDULING IN
SCHEDULING INTERACTIVE SYSTEMS

A scheduling algorithm with four priority classes.


SCHEDULING IN
SCHEDULING INTERACTIVE SYSTEMS

3. Multi-Queue & Multi-Level Feedback


Scheduling algorithms can be combined
Have multiple queues
Use a different algorithm among queues
Move processes among queues
Multiple queues represents different job types
Interactive, CPU-bound, batch, etc.
Queues have priorities
SCHEDULING IN
SCHEDULING INTERACTIVE SYSTEMS
SCHEDULING IN
SCHEDULING REAL-TIME SYSTEMS

Earliest Deadline First Scheduling


Each job has an arrival time and a deadline to finish
Assignments, exams*
Always pick the job with the earliest deadline to run

P1

P2

P3

You might also like