When several processes are ready, the operating system must choose which runs first. Try three policies on the same four processes and compare their waiting times.
A CPU scheduling simulator showing four processes on a Gantt chart
| Process | Arrival time | Burst time | Waiting time |
|---|
1. Choose a scheduling policy
2. Play the execution order
Average waiting time by policy (lower is better)
Editing arrival or burst times recalculates the results. Choose a policy and press Play schedule to reveal CPU execution from left to right.
Three ways to choose the next process
FCFS runs processes to completion in arrival order. It is simple, but a long process at the front makes short processes wait.
SJF chooses the shortest burst among processes that have arrived. It can reduce average waiting time, but burst lengths are difficult to predict and long jobs may starve if short jobs keep arriving.
Round robin gives each process a fixed time slice and then moves it to the back of the queue. Processes take turns, but a very small quantum increases context-switch overhead.
Calculating waiting time
Add all time spent ready but waiting for the CPU.
Waiting time = completion time − arrival time − burst time