Loading…
Loading…
Charting your lesson…
Opening your lesson…
CPU Scheduling Algorithms
Lesson 3 of 4
6 steps•about 12 min•12 flashcards
Step 1/ 61 min
When several processes are Ready, the scheduler decides who runs next. The chosen algorithm directly shapes responsiveness, fairness and throughput — and computing waiting/turnaround times by hand is a guaranteed exam exercise.
Core idea: a CPU scheduling algorithm picks the next Ready process for the CPU to optimise some metric — turnaround time (completion − arrival), waiting time (turnaround − burst), response time (first run − arrival), or throughput. Schedulers are non-preemptive (run to completion/block) or preemptive (can be interrupted).
Step 2/ 61 min
For a set of processes, build a Gantt chart of execution order, then per process:
Preemptive algorithms (SRTF, RR, preemptive priority) react to new arrivals and improve response time but add context-switch overhead. RR's quantum is a knob: too large → behaves like FCFS; too small → thrashing on context switches. SJF/SRTF minimise average waiting time but are impractical without burst prediction and can starve long jobs — real systems (Linux CFS) approximate "fairness" instead.
Step 3/ 61 min
Processes (arrival 0, bursts): P1=6, P2=8, P3=7, P4=3.
FCFS (order P1,P2,P3,P4): completions 6, 14, 21, 24.
SJF (shortest first: P4=3, P1=6, P3=7, P2=8): completions 3, 9, 16, 24.
Same jobs, same total time (24), but SJF's average waiting time (7.0) beats FCFS (10.25) — a concrete demonstration that scheduling order alone changes waiting time, and why SJF is optimal for it.
Step 4/ 61 min
Extremely common: "compute average waiting/turnaround time for FCFS/SJF/RR", "which algorithm minimises average waiting time?" (SJF), "what is the convoy effect / starvation / aging", and "preemptive vs non-preemptive". Drawing the Gantt chart correctly (especially with arrival times and RR quanta) is the graded skill.
Step 5/ 61 min
Forgetting to subtract arrival time when computing waiting time, or ignoring arrival times entirely in the Gantt chart. Waiting time = turnaround − burst, and turnaround = completion − arrival. With staggered arrivals you must also leave the CPU idle until the first process arrives, or every subsequent number is wrong.
Step 6/ 6· Worked examples2 min
Problem
Four processes arrive at time 0 with burst times P1=6, P2=8, P3=7, P4=3. Compute the average waiting time under (i) FCFS in arrival order P1,P2,P3,P4 and (ii) non-preemptive SJF. Compare.
Try it on paper first.
Recall
Keep this
CPU scheduling is a numerically heavy, high-frequency OS topic — expect Gantt-chart problems computing average waiting/turnaround time, plus conceptual questions on starvation and preemption. It's a scoring area if you know the formulas.
Non-preemptive: a process keeps the CPU until it blocks or finishes. Preemptive: the OS can forcibly take the CPU (e.g. on a timer or higher-priority arrival).
| Algorithm | Type | Key property |
|---|---|---|
| FCFS | non-preemptive | simple; convoy effect |
| SJF | non-preemptive | optimal avg wait; starvation |
| SRTF | preemptive SJF | optimal; needs burst prediction |
| Priority | either | starvation → fix with aging |
| Round Robin | preemptive | fair; depends on time quantum |
Gantt-chart numericals (compute avg waiting/turnaround for FCFS/SJF/RR), "which algorithm minimises waiting time?", "what is the convoy effect?", "how does aging prevent starvation?", and "effect of RR quantum size".
Non-preemptive: FCFS (convoy effect), SJF (optimal avg wait, starvation). Preemptive: SRTF, Round Robin (fair, quantum-sensitive), Priority (starvation→aging). Turnaround = Completion−Arrival; Waiting = Turnaround−Burst. SJF minimises average waiting time but needs burst prediction.
You've read 0 of 6 steps
Now lock it in — questions straight after reading are what make it stick.