First come first served
Three jobs wait in the ready queue, the list of jobs ready to run. A needs 100 seconds of CPU time; B and C need 10 each. All arrive at time 0. The scheduler, part of the kernel, picks who runs next.
First come first served (FCFS, also called FIFO) runs jobs in the order they arrived. Each job runs to the end before the next one starts. A, B and C arrived together in that order, so A goes first.
A holds the CPU from 0 to 100 seconds. B and C need only 10 seconds each, yet they sit in the queue the whole time. Short jobs stuck behind a long one: this is called the convoy effect.
B finally runs from 100 to 110, and C from 110 to 120. Turnaround is finish time minus arrival time. All three arrived at 0, so their turnarounds are 100, 110 and 120 seconds.
Average turnaround: (100 + 110 + 120) / 3 = 110 seconds. B and C each ran for 10 seconds but finished after more than 100. The order of the queue, not the work itself, made them slow.
Shortest job first
Same three jobs, new rule. Shortest job first (SJF) picks the ready job with the shortest run time, then the next shortest, and so on. A started job still runs to the end. The scheduler must know every run time in advance.
B runs from 0 to 10, C from 10 to 20, then A from 20 to 120. A now waits 20 seconds, but B starts at once and C waits only 10. The CPU still finishes all the work at 120.
Average turnaround: (10 + 20 + 120) / 3 = 50 seconds, less than half of FCFS's 110. When all jobs arrive together, SJF gives the lowest average turnaround of any order.
Where SJF breaks
Now B and C arrive at time 10. At time 0 only A is ready, so SJF starts A, and A runs to the end. B and C wait anyway: (100 + 100 + 110) / 3 = 103.33 seconds average.
SJF needs two things. It must know run times in advance, which a real OS rarely does. And to help late short jobs it must stop a running job, called preemption. Preemptive schedulers, such as round robin, come next.
What happens
;; step 1/10 · jobs job arrives needs (run time) A 0 100 s B 0 10 s C 0 10 s one CPU: one job runs at a time turnaround = time finished - time arrived (defined in the lesson on turnaround, response time and fairness)
FCFS and SJF here are non-preemptive: once a job starts it runs to the end. Adding preemption to SJF gives shortest time-to-completion first (STCF), which in the late-arrival case gets the average back down to 50 s (OSTEP 7.5). The worked example and its numbers (A 100 s, B and C 10 s; averages 110, 50 and 103.33 s) are from OSTEP chapter 7. Real CPU bursts are usually milliseconds, not seconds; the arithmetic is the same.