Run to the end
Three jobs, A, B and C, arrive together at time 0. Each needs 5 seconds of CPU. There is one CPU, so the scheduler, the part of the kernel that picks who runs next, must choose an order.
The simplest order: first in, first out (FIFO). The job at the head of the queue runs to the end, then moves to Finished and the next starts. A runs from 0 to 5 seconds, B from 5 to 10, C from 10 to 15.
Turnaround time is finish minus arrival: how long a job spent in the system. A took 5 seconds, B 10, C 15. The average is 10 seconds. Lower is better.
Response time is first run minus arrival: how long a job waits before it gets the CPU at all. A waits 0 seconds, B 5, C 10. The average is 5 seconds. A person typing into C would wait 10 seconds.
Taking turns
Round robin lets jobs take turns. A timer interrupt ends each time slice, here 1 second. The kernel saves the running job (a context switch), puts it at the back of the queue and starts the job at the head.
Same three jobs, same 15 seconds of work. Now A runs 1 second, then B, then C, then A again, round and round. A finishes at 13 seconds, B at 14, C at 15, each moving to Finished.
Every job starts within 2 seconds: A at 0, B at 1, C at 2. Average response drops from 5 seconds to 1. A person typing into any of them would see it react quickly.
But every job now finishes near the end: at 13, 14 and 15 seconds. Average turnaround rises from 10 seconds to 14. Taking turns stretched every job out.
The trade-off
Fairness asks how evenly the CPU is shared over a short stretch. In the first 3 seconds FIFO gives A all 3 and B and C nothing. Round robin gives each job 1 second: a perfectly even share.
Being fair on a short time scale gives fast response but slow turnaround. Running jobs to the end does the opposite. No scheduler wins every score, so a system picks what matters most: batch work or people waiting.
What happens
;; step 1/10 · jobs job arrives needs A t = 0 5 s of CPU B t = 0 5 s of CPU C t = 0 5 s of CPU total work 15 s on one CPU the question who runs next, and for how long? to compare answers we need scores (metrics)
The 1-second slice keeps the numbers easy, as in OSTEP's example. Real time slices are milliseconds long, and each must be a multiple of the timer-interrupt period. The figure ignores the cost of each context switch. It is not zero: OSTEP notes that with a 10 ms slice and a 1 ms switch cost, about 10% of the CPU is wasted, and switching also loses warm caches. That is why slices cannot be made tiny.