Operating System_scheduling
Operating System_scheduling
Systems
processor
Scheduling
Types of Scheduling
Medium
Long term Short term
term
scheduling scheduling
scheduling
◼ Max throughput
◼ Invoked when an event occurs that may lead to the blocking of the
current process or that may provide an opportunity to preempt a
currently running process in favor of another
Examples:
• Clock interrupts
• I/O interrupts
• Operating system calls
• Signals (e.g., semaphores)
Nonpreemptive Preemptive
◼ Currently running process
may be interrupted and
◼ Once a process is in the moved to ready state by
running state, it will the OS
continue until it terminates ◼ Decision to preempt may
or blocks itself for I/O be performed when a new
process arrives, when an
interrupt occurs that
places a blocked process in
the Ready state, or
periodically, based on a
clock interrupt
© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Process Scheduling Example
A
First-Come-First B
Served (FCFS) C
D
E
A
Round-Robin B
(RR), q = 1 C
D
E
A
Round-Robin B
(RR), q = 4 C
D
E
A
Shortest Process B
Next (SPN) C
D
E
A
Shortest Remaining B
Time (SRT) C
D
E
A
© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Highest Response B
A Comparison
of Scheduling
Policies
Process A B C D E
Arrival Time 0 2 4 6 8
Service Time (Ts) 3 6 4 5 2 Mean
FCFS
Finish Time 3 9 13 18 20
Turnaround Time (Tr) 3 7 9 12 12 8.60
Tr/Ts 1.00 1.17 2.25 2.40 6.00 2.56
RR q = 1
Finish Time 4 18 17 20 15
Turnaround Time (Tr) 4 16 13 14 7 10.80
Tr/Ts 1.33 2.67 3.25 2.80 3.50 2.71
RR q = 4
Finish Time 3 17 11 20 19
Turnaround Time (Tr) 3 15 7 14 11 10.00
Tr/Ts 1.00 2.5 1.75 2.80 5.50 2.71
SPN
Finish Time 3 9 15 20 11
Turnaround Time (Tr) 3 7 11 14 3 7.60
Tr/Ts 1.00 1.17 2.75 2.80 1.50 1.84
SRT
Finish Time 3 15 8 20 10
Turnaround Time (Tr) 3 13 4 14 2 7.20
Tr/Ts 1.00 2.17 1.00 2.80 1.00 1.59
HRRN
Finish Time 3 9 13 20 15
Turnaround Time (Tr) 3 7 9 14 7 8.00
Tr/Ts 1.00 1.17 2.25 2.80 3.5 2.14
FB q = 1
© Finish Time
2017 Pearson Education, Inc., Hoboken, NJ.4All rights reserved.
20 16 19 11
First-Come-First-Served
(FCFS)
◼ Simplest scheduling policy
◼ Performs much better for long
◼ Also known as first-in-first-out processes than short ones
(FIFO) or a strict queuing
scheme ◼ Tends to favor processor-bound
processes over I/O-bound
◼ As each process becomes ready, processes
it joins the ready queue
◼ The CPU is allocated to the process with the highest priority (smallest integer
highest priority)
◼ Preemptive
◼ Nonpreemptive
◼ SJF is priority scheduling where priority is the inverse of predicted next CPU
burst time
P1 10 3
P2 1 1
P3 2 4
P4 1 5
P5 5 2
◼ Run the process with the highest priority. Processes with the same priority run round-
robin
◼ Example:
P1 4 3
P2 5 2
P3 8 2
P4 7 1
P5 3 3
◼ Three queues:
◼ Q0 – RR with time quantum 8 milliseconds
◼ Q1 – RR time quantum 16 milliseconds
◼ Q2 – FCFS
◼ Scheduling
◼ A new process enters queue Q0 which is served in
RR
◼ When it gains CPU, the process receives 8
milliseconds
◼ If it does not finish in 8 milliseconds, the process is
moved to queue Q1
◼ At Q1 job is again served in RR and receives 16
additional milliseconds
◼ If it still does not complete, it is preempted and
moved to queue Q2