Operating System - Scheduling
Operating System - Scheduling
Management
Scheduling
Scheduling
Objectives of Scheduling
Maximize
assigned to process
Class of job (batch or online)
Resource requirements
I/O
or CPU bound
Resources
used to date
Waiting time to date
Static
Dynamic
3
CPU-bound or I/O-bound
Processor
Example: Proportional
Hazard Model
I/O device
Example: Database
Updates
Levels of Scheduling
High
( in seconds or \minutes)
Medium ( in seconds or \minutes)
Low ( in microseconds)
Preemptive
P2
P1
Blocked
or ready
Non-preemptive
Processor
P2 P1
Ready
P2
terminates
P1
Blocked
7
Dispatcher
Module that gives the control of the CPU to the
process selected by the scheduler
Dispatching involves:
Switching context
Switching to user mode
Jumping to the proper location in the user program
Definitions
Throughput
Number of processes that are completed per time unit.
Turnaround time
The interval from the time of submission to the time of
completion
Waiting time
Is the sum of periods spent waiting in the ready queue
Response time
Is the period from the time of submission to the first
response
9
Scheduling Policies
First-come-First-serve
(FCFS)
Shortest Job First (SJF)
Priority scheduling
Round Robin (RR)
Multilevel queues and Feedback
queues
10
CPU Scheduling
Decide which
which of
of the
the processes
processes
Decide
in the
the ready
ready queue
queue is
is to
to be
be
in
allocated to
to the
the CPU
CPU
allocated
11
First-come-First-serve (FCFS )
Blocked
C
P
U
Exit
Ready Queue
s
s
e
oc
r
P
y
r
t
En
12
FCFS
It is a non-preemptive algorithm
The process that requests the CPU gets it first
Implemented with a FIFO queue
PCB of a newly entered process is linked to the
tail of the queue
Free CPU is allocated to the process at the head
of the queue
The running process is removed from the queue
The average waiting time may vary substantially
and not optimal for all process
There is a convoy effect : all processes wait for
one big process to free the CPU
Disastrous for time-sharing systems
13
U
1
3
o
r
P
s
s
e
c
y
r
t
En
Ready Queue
14
SJF
15
Priority Scheduling
16
Timeout ( 2ms)
C
P
U
Exit
s
s
e
oc
r
P
y
r
t
En
Ready Queue
17
RR
18
Minimize
Minimize
the
the
overhead
overhead
RR
Long timequantum
FCFS
Typically 10-20
10-20 milliseconds
milliseconds
Typically
19
20
21
22
Example - (MFQ)
8
(RR)
16
(RR)
FCFS
C
P
U
*
*
23
MFQ Parameters
1.
2.
3.
4.
5.
Number of queues
Scheduling algorithm for each queue
When to upgrade a process to higher
priority queue?
When to demote a process to lower
priority queue?
Which queue a process will enter when
that process needs service?
24