What is CPU Scheduling?
CPU scheduling, told as a story about the garage chief deciding which car gets the one lift next.
This garage IS a computer system.One lift (the CPU), but cars (jobs) keep arriving.
Pick the car order carelessly, and a slow car that came first blocks all the others.Even a quick job waits forever behind a long one.
CPU scheduling = the chief writing a rule on the board to set the car order.Which rule is used decides who gets the lift first.
FCFS is simple but a long car blocks the rest; SJF shortens waits but pushes long cars back.Round-robin is fair, but switching cars costs a little time each turn.
No single rule is perfect.Fairness and speed often pull against each other.
CPU scheduling = the rule that decides which car (job) gets the one lift (CPU) next when several arrive at once.
The OS decides the order in which processes get the CPU. FCFS, SJF (Shortest Job First), Round Robin (time-sliced), and Priority Scheduling are the classic algorithms. FCFS is simple but suffers the convoy effect; SJF minimizes average wait but can starve long jobs; Round Robin shares turns fairly via a time quantum but pays a context-switch cost each turn.
When grown-ups say it
- FCFS
- Load cars in the order they arrived. Simple, but a long car blocks everyone behind it.
- SJF
- Finish the shortest job first. Lowers average wait, but can starve long jobs.
- Round Robin
- Give everyone a small, rotating turn. Fair, but each switch costs a little time (context switch).
- Starvation
- A car that keeps getting bumped down the board. Starvation is covered alongside deadlock. → the garage frozen waiting on each other's keys
- Synchronization
- The rule for handing out the lift key. Scheduling is "who goes first" — this is "don't touch at once." → there's only one lift key
- Process/Thread
- One car vs. several hands working the same car. The actual scheduling unit is often the thread. → one car, many hands
- Time Complexity
- The ruler for how fast work grows as cars pile up. Re-sorting the board each time is measured with this ruler too. → how much slower as cars pile up
- Orchestration
- A similar 'ordering' idea in the SRE field. A similar problem shows up one layer up, at the service/container level. → orchestration in the SRE field