You are on page 1of 24

Process

Management
Scheduling
Scheduling

Objectives of Scheduling
Maximize

the system throughput


Be fair to all users
Provide tolerable response
Degrade performance gracefully
Be consistent and predictable

Criteria for Scheduling


Priority

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 versus Non-preemptive

Preemptive

Scheduler removes a process from the


processor so that another process can run
generates more context switches
Greater overheads
Necessary for on-line and essential for realtime systems
Processor
P2 P1
Ready

P2

P1

Blocked
or ready

Preemptive versus Non-preemptive

Non-preemptive

Once given the processor, a process stops


running only when
It has terminated
it has incurred an I/O wait
A process only voluntarily gives up processor

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

Dispatch latency time it takes the dispatcher


to stop one process and start another

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

Shortest Job First (SJF )


Blocked
C
P
2

U
1
3

o
r
P

s
s
e
c

y
r
t
En

Ready Queue

14

SJF

Selects the process from the ready queue with shortest


estimated run-time (CPU burst)
Essentially a priority scheme
It is an optimal algorithm as the average waiting time is
minimum
Problem: prevents very log job from getting the CPU starvation
Suitable for batch processing (high level scheduling)
Problem: what is the length of next CPU burst?
Possible to predict the value - exponential average of the
measured length of previous CPU bursts
Primarily non-preemptive but possible to design a
preemptive version

15

Priority Scheduling

A priority is associated with each process

CPU is allocated to the process with highest priority

Equal processes are scheduled in FCFS order

Priorities can be defined internally or externally

Internal : ratio of average I/O burst to average CPU burst

External: importance of the project, fund resources

Can be preemptive or non-preemptive

Major problem : starvation of low priority processes

Solution to starvation: aging - is a technique of gradually


increasing the priority of processes that wait in the system
for a long time

16

Round Robin Scheduling (RR)


Blocked

Timeout ( 2ms)

C
P
U
Exit

s
s
e
oc
r
P

y
r
t
En

Ready Queue
17

RR

Similar to FCFS with preemption. A must for time-sharing


system

A process is selected from the ready queue in FIFO


sequence, new processes are added to the tail of the queue

CPU is allocated to each process for a fixed length of time


called time quantum or time slice

Then it is interrupted ( by the hardware timer) and sent back


to the ready queue

If the CPU burst of the process is less than the time


quantum, the process releases the CPU earlier

Preemption occur at the end of time quantum

Has significant overhead as there is a context switch at end


of each quantum. Average waiting time is pretty long

18

What Will Be the Size of


Time Quantum ?
Userresponse
response
User
timeshould
shouldnot
not
time
bereduced
reduced
be

Minimize
Minimize
the
the
overhead
overhead

RR

Long timequantum

FCFS

Typically 10-20
10-20 milliseconds
milliseconds
Typically
19

Multilevel Queue Scheduling

Partition the ready queue into several separate


queues.
Processes are permanently assigned to one queue
based on properties like type, size and priority.
Each queue will have its own scheduling algorithm.
Processes do not move from one queue to another.
Scheduling between the queues fixed priority
preemptive scheduling.
Scheduling between the queues time slice based.

20

Multilevel Queue Scheduling


SystemProcesses
Processes
System
InteractiveProcesses
Processes
Interactive
InteractiveEditing
EditingProcesses
Processes
Interactive
BatchProcesses
Processes
Batch
StudentProcesses
Processes
Student

21

Multilevel Feedback Queue


Scheduling (MFQ)

Processes can move between queues.


Separate processes with different CPU bursts.
Processes with short CPU bursts are put in higher
priority queues. In other words I/O bound processes are
put in higher priority queues
If a process uses too much CPU time, it is moved to a
lower priority queue.
Processes in a lower level queue are allocated the
processor only when higher level queues are empty
Process waiting too long in lower priority queue are
moved upwards to a higher priority queue (aging
preventing starvation).

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

You might also like