Professional Documents
Culture Documents
Chapter 5 (B) - CPU Scheduling
Chapter 5 (B) - CPU Scheduling
Operating System Concepts – 9th Edition Silberschatz, Galvin and Gagne ©2013
Scheduling Algorithm
Operating System Concepts – 9th Edition 5.2 Silberschatz, Galvin and Gagne ©2013
First- Come, First-Served (FCFS) Scheduling
Operating System Concepts – 9th Edition 5.3 Silberschatz, Galvin and Gagne ©2013
FCFS Scheduling (Cont.)
Operating System Concepts – 9th Edition 5.4 Silberschatz, Galvin and Gagne ©2013
Shortest-Job-First (SJF)
Operating System Concepts – 9th Edition 5.5 Silberschatz, Galvin and Gagne ©2013
Example of SJF
P4 P1 P3 P2
0 3 9 16 23
Operating System Concepts – 9th Edition 5.6 Silberschatz, Galvin and Gagne ©2013
Shortest-Remaining-Time-First (SRTF)
● Preemptive version of SJF is called shortest-remaining-time-first
P1 P2 P4 P1 P3
0 1 5 10 17 26
Operating System Concepts – 9th Edition 5.7 Silberschatz, Galvin and Gagne ©2013
SRTF/SJF (Preemptive): Question?
Operating System Concepts – 9th Edition 5.8 Silberschatz, Galvin and Gagne ©2013
SRTF/SJF (Preemptive) - Solution
Process Arrival Time Burst Time Turn-Around Waiting Time
P1 2 6 15-2=13 13-6=7
P2 5 2 2 0
P3 1 8 22 14
P4 0 3 3 0
P5 4 4 6 2
turn-around time = CT - AT
Waiting time = TAT - BT
P4 P1 P5 P2 P5 P1 P3
0 3 4 5 7 10 15 23
Operating System Concepts – 9th Edition 5.9 Silberschatz, Galvin and Gagne ©2013
Round Robin (RR)
● Each process gets a small unit of CPU time (time quantum q).
After this time has elapsed, the process is preempted and
added to the end of the ready queue.
● If there are N processes in the ready queue and the time
quantum is q, then each process gets 1/N of the CPU time in
chunks of at most q time units at once. No process waits
more than (N-1)q time units.
● Timer interrupts every quantum to schedule next process
● Performance
● q large ⇒ FIFO
● q small ⇒ q must be large with respect to context switch,
otherwise overhead is too high
Operating System Concepts – 9th Edition 5.10 Silberschatz, Galvin and Gagne ©2013
Example of RR with Time Quantum = 4
P1 P2 P3 P1 P1 P1 P1 P1
0 4 7 10 14 18 22 26 30
Operating System Concepts – 9th Edition 5.11 Silberschatz, Galvin and Gagne ©2013
Round Robin (TQ = 2) : Question?
Operating System Concepts – 9th Edition 5.12 Silberschatz, Galvin and Gagne ©2013
Round Robin (TQ = 2) - Solution
Process Arrival Time Burst Time Turn-Around Waiting Time
P1 0 5 12-0=12 12-5=7
P2 1 4 10 6
P3 2 2 4 2
P4 4 1 5 4
P1 P2 P3 P1 P4 P2 P1
Ready Queue:
turn-around time = CT - AT
● Round Robin (Preemptive) scheduling chart: Waiting time = TAT - BT
P1 P2 P3 P1 P4 P2 P1
0 2 4 6 8 9 11 12
Operating System Concepts – 9th Edition 5.13 Silberschatz, Galvin and Gagne ©2013
SRTF/RR: Class Activity?
Operating System Concepts – 9th Edition 5.14 Silberschatz, Galvin and Gagne ©2013
End of Chapter 5
Operating System Concepts – 9th Edition Silberschatz, Galvin and Gagne ©2013