Chapter 03 New 2023
Chapter 03 New 2023
CPU Scheduling
Outline
Introduction to scheduling
Process behavior
When to schedule
Categories of scheduling algorithms
Scheduling algorithms goals (criteria)
Scheduling algorithms
Scheduling in batch systems
Scheduling in interactive systems
Scheduling in Real time systems
CPU scheduling
Waiting time Amount of time a process has been waiting in the ready
queue.
Burst Time Time of execution, when process is in Processor.
Response time Amount of time it takes from when a request was
submitted until the first response is produced, not output (for time-sharing
environment).
rt = t(first response) – t(submission of request)
Scheduling algorithms Goals
All systems
Fairness is important
Comparable processes should get fair share
Enforcing systems policy
Safety control and payroll applications in a nuclear reactor
Keeping all parts of the computer busy
I/O bound and CPU- bound can be run together.
Scheduling algorithms Goals…
Batch systems
Throughput - maximum jobs per hr.
Turn around time – minimize time between submission and termination
CPU utilization – keep the CPU busy all the time
Interactive systems
Response time – respond to request quickly
Proportionality –meet users expectations.
Scheduling algorithms Goals…
Real-Time
Meeting deadlines – avoid losing of data
Predictability – avoid quality degradation in multi-media systems
Scheduling in Batch systems
FCFS
SJF
Short time remaining next
First Come First Served
The process that requests the CPU first is allocated the CPU first.
It’s the simplest of all algorithms
It’s non-preemptive
A blocked process come to an end of the queue when it’s ready to be
executed
Easy to understand and to program
A single linked list keeps track of all ready state processes
The greater disadvantage is when executing I/O bound processes.
First Come First Served
0 24 27 30
Waiting time for P1 = 0; P2 = 24; P3 = 27
Average waiting time: (0 + 24 + 27) / 3 = 17 (milliseconds)
Average turn-around time: (24 + 27 + 30)/3 = 27
Shortest Job First
P3 P2 P4 P1
0 1 5 10 16
Average waiting time = (0 + 1 + 5 + 10)/4 = 4
Average turn-around time = (1 + 5 + 10 + 16)/4 = 8
Non-Pre-emptive SJF
P1 P3 P2 P4
0 3 7 8 12 16
0 2 4 5 7 11 16
1 0 8 20 12 0
2 1 4 9 5 0
3 2 2 2 0 0
4 3 1 2 1 1
5 4 3 9 6 1
6 5 2 2 0 0
Shortest Remaining Time First
Scheduling in interactive systems
It’s better to set one quantum enough amount of time say 100msec to
improve the efficiency.
But here what if ten users press return button at the same time?
The two main things as a summary
Setting the quantum two short causes to many process switches that will result in
performance degradation.
But setting it too long may cause poor response to short interactive commands.
Round-Robin….
Unix system has nice which allows the user to voluntarily reduce its
priority level.
Process priority can be given statically and dynamically
Statically-Role and privilege assignment in MIS systems
Dynamically- I/O bound processes should be given the highest priority after waiting
for I/O response and asks to run again.
This avoid unnecessary memory hold time
A simple algorithm for giving this service is to set the priority to 1/f where f is fraction of
the last quantum that the process used.
For e.g a process that uses 1 msec of its 50 msec quantum then it will be given priority
level equivalent to its quantum.
Priority scheduling….
Processes in the highest priority class will run for 1 quantum and
processes in the next highest class will run for 2 quanta processes in the
next class will run for 4 quanta and so on.
Consider how a process that needs100 quanta to continuously run and finish its
computation. It would only need 7 swaps unlike 100 swaps in pure round- robin.
Multiple Queues….. Priority level examples
Multiple queues….
Algorithm evaluation
Scheduling in different OS
windows
Solaris
Unix
Mobile OS
*******End of Chapter 3*************