Menu

Earn Premium with Referrals

Invite your friends and earn Premium rewards through our referral program.

See how it works and start inviting friends.

CPU Scheduling Algorithms
OS

CPU Scheduling Algorithms

Learn how the OS decides which process runs next: FCFS, SJF, Round Robin, and more.

The CPU scheduler selects from the ready queue which process runs next. The goal: maximize throughput and fairness, minimize waiting time and response time.

Types of Schedulers

SchedulerWhat it doesFrequency
Long-term (Job)Loads processes from disk into memoryLow — controls multiprogramming degree
Short-term (CPU)Picks which ready process gets CPU nextVery high — every few ms
Medium-termSwaps processes in/out of memory to diskMedium — handles thrashing

Scheduling Criteria

MetricDefinitionWant
ThroughputProcesses completed per unit timeHigh
Turnaround timeTotal time from submission to completionLow
Waiting timeTotal time spent in ready queueLow
Response timeTime from submission to first responseLow (critical for interactive systems)

Algorithms Compared

AlgorithmPreemptive?Starvation?Best for
FCFSNoNoSimple batch systems
SJFNoYes (long jobs)When burst times are predictable
SRTFYesYesWhen burst times are predictable
Round RobinYesNoTime-sharing, interactive systems
PriorityOptionalYes (can fix with aging)Systems with clear priority tiers

FCFS (First-Come, First-Served)

Non-preemptive. Processes run in arrival order.

  • Convoy effect: short processes wait behind a long CPU-bound process, wasting CPU when short processes could be running while the long one does I/O.

SJF (Shortest Job First) / SRTF

SJF is non-preemptive; SRTF is preemptive (Shortest Remaining Time First).

  • Optimal in terms of average waiting time (if burst times are known)
  • Starvation: long processes may never get CPU if short jobs keep arriving

Round Robin

Each process gets a fixed time quantum (typically 10-100ms).

  • Quantum too large → degrades to FCFS
  • Quantum too small → too many context switches, high overhead

Priority Scheduling

Higher priority processes run first.

  • Starvation solved by aging — gradually increase priority of waiting processes
  • Priority inversion: a low-priority process holds a lock needed by a high-priority one

Q: What are the three types of schedulers?

A: Long-term (loads processes into memory), short-term (allocates CPU), medium-term (swaps processes in/out of memory). The short-term scheduler runs the most frequently — every few milliseconds.

Q: What is the Convoy Effect?

A: In FCFS, a long CPU-bound process holds the CPU while short I/O-bound processes wait. The I/O devices sit idle, then get flooded when the long process finally finishes. It causes poor resource utilization.

Q: What is Starvation and how is it solved?

A: Starvation occurs when a process never gets CPU because higher-priority or shorter processes keep arriving. Solved with aging — gradually increase the priority of waiting processes.

Q: How does time quantum affect Round Robin performance?

A: Too large → behaves like FCFS, poor response time. Too small → excessive context switching overhead, reduced throughput. Ideal quantum is just larger than most CPU bursts (~80th percentile).

Q: What is priority inversion?

A: A high-priority process is blocked because a low-priority process holds a needed lock. The low-priority process can’t run because medium-priority processes preempt it. Solved with priority inheritance (temporarily boost the low-priority process’s priority).

My Private Notes

Notes are auto-saved locally to this device.