Browse⌘K
tsfeatured.ts
tsxscheduler.tsx
tsxscheduler.tsxLab · interactive

cpu scheduler · FCFS / SJF / SRTF / RR

The same workload, four scheduling policies, very different averages. Drag arrivals and bursts, watch the Gantt chart redraw, and try to find the policy that wins for your workload.

Objective
Build intuition for why scheduling policy matters more than CPU speed for response time, and why one policy isn't 'best' — it depends entirely on the shape of the workload.
Challenge
Pick a workload and find the policy + quantum that gets avg wait below 4. Then make it worse by re-shaping the workload. Convoy effect is real.
Policy
FCFS
Avg wait
8.75
Avg turnaround
15.25
CPU util
100%
policy
preset
gantt0 → 26
P1
P2
P3
P4
01234567891011121314151617181920212223242526
idarrivalburstwaitturnaroundresponse
080
7117
101910
182318
avg wait
8.75
avg turnaround
15.25
avg response
8.75
cpu util %
100

Source

// scheduler · CSV-driven simulator (Project 2 in the OS Stack repo)
// Each scheduler picks the next process at every dispatch decision.
//
// FCFS  -> first-come-first-served:      finish current before next
// SJF   -> shortest-job-first:           non-preemptive — fairness can suffer
// SRTF  -> shortest-remaining-time-first: preemptive variant of SJF
// RR    -> round-robin:                  time-slice of Q ticks, then rotate

typedef struct proc { int pid; int arrival; int burst; int priority; } proc;
proc* schedule_fcfs(proc *ready, int n);
proc* schedule_sjf (proc *ready, int n);
proc* schedule_srtf(proc *ready, int n, int now);
proc* schedule_rr  (proc *ready, int n, int *active_q);

What's really happening

Every scheduler picks the next process at every dispatch decision — a context switch trigger. FCFS only re-dispatches when the current process finishes. SJF and SRTF look at remaining work. RR adds a clock-driven preemption every Q ticks. The differences in avg wait trace directly to how aggressively the policy interrupts long jobs.

Convoy effect: when a long job arrives first, FCFS makes every later short job wait for it. SJF/SRTF fix this by reordering. Try the convoy preset on FCFS vs SRTF and watch the average wait fall by 4–6×.

RR's knob: small Q means more context switches (overhead this simulator ignores) but better response time. Large Q approaches FCFS behavior. Real schedulers like CFS use a virtual-runtime heuristic to dodge the convoy without paying the SJF oracle cost of knowing each job's burst length up front.

● open to SWE roles·scheduler.tsx·UTF-8·github: …
·resume·contact··