CS Interview Prep · Operating Systems
CPU Scheduling for Interviews: the only guide you need
FCFS, SJF, SRTF, Round Robin and Priority — explained with worked Gantt charts, the exact formulas, and the traps interviewers and GATE love to set. Then go run every example yourself in the free simulator.
What CPU scheduling actually is
On a single CPU core, only one process runs at a time. When multiple processes are ready, the operating system's scheduler picks which one gets the CPU next. The goal depends on the system: minimise average waiting time, maximise throughput, guarantee responsiveness, or be fair. No single algorithm wins on every metric — which is exactly why interviewers ask about the trade-offs.
Three numbers matter for almost every question:
- Completion Time (CT): when a process finishes.
- Turnaround Time (TAT) = CT − Arrival Time. Total time in the system.
- Waiting Time (WT) = TAT − Burst Time. Time spent waiting, not running.
Average waiting time and average turnaround time are just the means across all processes. Response time — first time a process gets the CPU minus its arrival — matters for interactive systems.
1. FCFS — First Come, First Served
The ready queue is a plain FIFO. Whoever arrives first runs first, to completion. It's non-preemptive and trivially fair in arrival order — but it suffers the convoy effect: one long process at the front makes everyone behind it wait, ballooning average waiting time.
Interview trap: put a burst-20 process first and three burst-2 processes behind it. FCFS gives a terrible average; SJF on the same set is dramatically better. Being able to say why instantly signals you understand the convoy effect.
2. SJF — Shortest Job First (non-preemptive)
Among the processes that have arrived, run the one with the smallest burst time next. SJF is provably optimal for minimising average waiting time when all jobs are available — but it needs to know burst times in advance (in practice, estimated), and it can starve long jobs if short ones keep arriving.
3. SRTF — Shortest Remaining Time First (preemptive SJF)
The preemptive version: whenever a new process arrives, compare its burst to the remaining time of the running process and switch if it's shorter. SRTF gives the lowest average waiting time of the classic algorithms, at the cost of more context switches and worse starvation for long jobs.
Interview trap: SRTF questions punish arithmetic slips because you re-evaluate at every arrival. Build the Gantt chart one time-unit at a time and you won't miss a preemption.
4. Round Robin — fair time slicing
Each process gets a fixed time quantum; if it doesn't finish, it goes to the back of the ready queue. Round Robin is preemptive, fair, and great for responsiveness — the backbone of interactive scheduling.
The quantum is everything. Too large and RR degrades to FCFS. Too small and context-switch overhead dominates. A common rule of thumb: the quantum should be slightly larger than the time for a typical interaction, so ~80% of bursts finish within one quantum.
Interview trap: the exact queue order after a preemption. When a process's quantum expires at the same instant another arrives, conventions differ on who enters the queue first — state your assumption explicitly and stay consistent.
5. Priority Scheduling
Each process has a priority; the highest-priority ready process runs (lower number usually = higher priority). It can be preemptive or not. The classic problem is starvation: a low-priority process may never run. The fix is aging — gradually raise the priority of waiting processes so they eventually run.
The 60-second comparison table
| Algorithm | Preemptive? | Optimises | Main risk |
|---|---|---|---|
| FCFS | No | Simplicity | Convoy effect |
| SJF | No | Avg waiting time | Starvation, needs burst estimate |
| SRTF | Yes | Avg waiting time (best) | Starvation, many switches |
| Round Robin | Yes | Responsiveness, fairness | Quantum tuning |
| Priority | Either | Importance ordering | Starvation (use aging) |
Don't just read it — run it
You will forget this in a week if you only read it. You won't forget it if you operate it: change a quantum and watch the average waiting time move, drop in a long job and watch FCFS convoy or SJF starve. That muscle memory is what gets you through the interview when you're nervous.
SimDojo's CPU scheduling simulator is free — no signup. Edit the process table, switch algorithms, and an AI tutor reads your exact Gantt chart and explains every result. Hit "new AI scenario" for infinite fresh practice.
Frequently asked interview questions
Which scheduling algorithm gives the minimum average waiting time?
SRTF (preemptive SJF) gives the lowest average waiting time, with non-preemptive SJF optimal when all jobs arrive together.
What is the convoy effect?
In FCFS, a long process at the front of the queue forces many short processes to wait, sharply raising average waiting time.
How do you prevent starvation in priority scheduling?
Use aging: gradually increase the priority of processes that have waited a long time so they eventually get the CPU.
What happens if the Round Robin time quantum is very large or very small?
Very large → it behaves like FCFS. Very small → context-switch overhead dominates and throughput drops.
Want the rest — paging, deadlocks, networks and DBMS — as interactive simulators with the AI tutor? Unlock all 12 for a one-time ₹499 →