Scheduling
Scheduling
Scheduling
In multiprogramming systems, the OS
decides which one to activate when there is
more than one runnable process (in the ready
queue).
Preemptive scheduling
Force the current executing processes to release
the CPU on certain events such as clock interrupt,
I/O interrupts or a system call. (with suspension).
Common Scheduling
Algorithms
Non-Preemptive Preemptive
FCFS RR
0 24 27 30
P2 P3 P1
0 3 6 30
a) Process BT b) Process BT
A 24 P1 4
B 10 P2 1
C 3 P3 8
Examples:
2. Calculate the TAT and WT of each process.
Consider the process arrival and burst times of
these processes as shown below.
Process BT AT Process BT AT
A 10 0 P1 8 0.0
B 5 12 P2 4 0.4
C 2 13 P3 3 8.2
D 1 18 P4 2 14.6
E 5 20 P5 1 16.0
Seatwork
Calculate the CPU Process AT BT
Utilization, average J1 13 4
TAT and WT for the J2 5 6
execution of the J3 3 6
process below.
J4 24 10
Consider their arrival
times and their burst J5 15 7
times J6 18 7
J7 14 8
Process’ CPU and I/O
requests
CPU and I/O requests
use any of the CPU
scheduling algorithm.
0 3 7 8 12 16
0 2 4 5 7 11 16
Process BT AT Process BT AT
A 10 0 J1 6 11
B 6 5 J2 8 0
C 7 7 J3 12 4
D 3 6 J4 2 2
E 1 3 J5 5 5
Priority Scheduling Algorithm
(PSA)
Priority number (integer) is associated with
each process
CPU is allocated to the process with the
highest priority (smallest integer ≡ highest
priority)
Preemptive
Non-Preemptive
PSA
SJF is a priority scheduling where priority
is the predicted next CPU burst time
Problem:
Starvation – low priority processes may never
execute
Solution:
Aging – as time progresses increase the
priority of the process
Sample Problem #1:
Process BT PL (HP = 1)
P1 8 4
P2 1 3
P3 3 2
P4 4 1
P4 P3 P2 P1
0 2 4 5 7 8 16
Non-Preemptive PSA: P1 P4 P3 P2
0 8 11 12 15 16
Preemptive PSA: P2 P P3 P3
P1 1 P4 P1
0 3 4 5 7 11 12 16
Round Robin (RR)
Scheduling
Process gets a small unit of CPU time (time
quantum), usually 10-100 milliseconds. After
this time has elapsed, the process is preempted
and added to the end of the ready queue.
P1 P2 P3 P4 P1 P3 P4 P1 P3 P3
0 20 37 57 77 97 117 121 134 154 162
Your turn:
Given the following Job AT BT PL
HPL=1
jobs, schedule using
1 0 18 3
PPSA and RR
(QT=4). 2 8 8 2
Q1: RR Q=3 B 13 3
Q2: RR Q=5 C 5 0
Q3: FCFS D 6 1
E 18 1
Try it!
Job BT AT
Schedule using an
A 24 32
MLFQ:
B 36 15
Q1: RR with Q=4
C 17 0
Q2: RR with Q=10
D 9 1
Q3: FCFS
E 15 17