SCHEDULER←020406080100120CPUFCFS avg020406080100120SJF avg020406080100120SJF, late avgA100 sB10 sC10 sA100 sB10 sC10 sA100 sB10 sC10 s
Back: the scheduler and the ready queue (block length = run time)Front: the CPU and one timeline per run, 0 to 120 s, with the average turnaroundBlocks: jobs hopping onto the timeline at their start time; the pin is the clockAt the back, the scheduler and the ready queue, where each job is a block as long as its run time. In front, the CPU and three timelines from 0 to 120 seconds, one per run, each with its average turnaround. FCFS runs A first, so B and C wait 100 seconds: average 110. SJF runs B, C, then A: average 50. With B and C arriving at 10, SJF has already started A and cannot stop it: average 103.33. SJF gives the lowest average turnaround only under the assumptions of the example: every job arrives at the same time, uses only the CPU, and its run time is known. A general-purpose OS usually knows very little about how long a job will run.

First come first served

  1. 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.

Shortest job first

Where SJF breaks

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.