What Is a Scheduler in an Operating System?

A scheduler is the part of the operating system kernel that decides which process or thread runs on each CPU core next, and for how long. At any moment a machine has more runnable threads than cores. The scheduler keeps a ready queue of those threads, picks one by a fixed rule, and gives it the core for a short time slice. When the slice ends, or the thread blocks on input or output, the scheduler picks again.

In plain words, a scheduler shares a small number of cores among a large number of tasks so that all of them make progress. A laptop with 8 cores and a few thousand threads makes this decision hundreds of times per second.

The three schedulers in a textbook

Three separate decisions are described as scheduling, and older textbooks give each one its own name.

SchedulerDecisionHow often it runs
Long-term (job scheduler)Which new programs are admitted into memory at allRarely; mostly in batch systems
Medium-termWhich waiting processes are swapped out of memory to free spaceOccasionally, under memory pressure
Short-term (CPU scheduler)Which ready thread gets the core nextEvery few milliseconds

Modern desktop and server systems have no distinct long-term scheduler. Every program you launch is admitted at once. When people say "the scheduler" they mean the short-term CPU scheduler, and the rest of this page does too.

The scheduler has a helper called the dispatcher. The dispatcher performs the actual switch. It saves the state of the outgoing thread and loads the state of the incoming one.

The goals a scheduler balances

No single rule is best for every workload, because the goals conflict.

  • CPU utilization. Keep every core busy while there is runnable work.
  • Throughput. Finish as many tasks per second as possible.
  • Turnaround time. Cut the time from when a task is submitted to when it finishes.
  • Waiting time. Cut the time a task sits in the ready queue.
  • Response time. For interactive work, cut the delay between a keypress and the first visible reaction.
  • Fairness. Give every task a share of the CPU. A task that never gets its share is said to starve.

A batch system optimizes throughput. A desktop optimizes response time. A real-time controller optimizes meeting deadlines, and it accepts lower throughput to do it.

Scheduling algorithms compared

AlgorithmRuleMain weakness
First come, first served (FCFS)Run tasks in the order they arrive, each until it finishesOne long task delays every short task behind it (the convoy effect)
Shortest job first (SJF)Run the task with the smallest expected CPU burst nextNeeds a prediction of run time; long tasks can starve
Shortest remaining time first (SRTF)Preemptive SJF: switch when a shorter task arrivesSame prediction problem, more context switches
Round robin (RR)Each task runs for a fixed quantum, then goes to the back of the queueA small quantum wastes time on switches; a large one hurts response time
Priority schedulingRun the highest priority ready taskLow priority tasks starve unless priority is raised over time (aging)
Multilevel feedback queue (MLFQ)Several queues by priority; a task that uses its full quantum moves down, one that blocks early stays upMany tunable parameters; a task can game it by yielding just before the quantum ends
Completely Fair Scheduler (CFS, Linux)Track how much CPU time each task has had; run the one with the least, weighted by nice valueFairness is measured over a short window, so bursty interactive tasks can still see delay

Windows uses a preemptive priority scheduler with 32 priority levels. It gives a temporary priority boost to threads that wake up after I/O, which keeps interactive programs responsive. Linux used CFS as its default for a long time. From kernel 6.6 the default is EEVDF (earliest eligible virtual deadline first), which keeps the fairness accounting of CFS and adds a deadline per task to cut latency. Real-time threads on Linux use separate FIFO and round robin policies.

Preemptive and cooperative scheduling

A preemptive scheduler can take the core away from a running thread at any time. It does this on a timer interrupt, or when a higher priority thread becomes ready. Every mainstream desktop and server OS is preemptive.

A cooperative scheduler waits for the running task to give up the core on its own. Classic Mac OS and Windows 3.1 worked this way. So do many language runtimes, such as the JavaScript event loop. One task that never yields freezes everything else, which is why operating systems moved to preemption.

Context switching, the cost of every decision

A context switch is the act of stopping one thread and starting another on the same core. The kernel saves the registers, program counter and stack pointer of the outgoing thread into its control block. It then loads the same fields for the incoming thread. Switching between two processes also changes the memory map, which flushes part of the address translation cache.

The direct cost is a few microseconds. The indirect cost is larger, because the incoming thread finds the CPU caches full of another thread's data. This is why the time quantum matters. A quantum of a few milliseconds keeps switch overhead under about one percent while still giving interactive programs quick turns.

How to Prepare

Scheduling questions appear in operating systems interviews and in the concurrency part of coding interviews.

  • Define scheduler, context switch, time quantum and starvation in one sentence each. Those four terms cover most follow-up questions.
  • Work one small example by hand. Take four tasks with different burst times and compute the average waiting time under FCFS, SJF and round robin with a quantum of 2.
  • Connect the scheduler to your own code. Thread pools, locks and blocking calls all change what the scheduler sees.

Grokking Multithreading and Concurrency for Coding Interviews covers threads, how the scheduler runs them, and the synchronization problems that follow.

Grokking the Coding Interview covers the problem patterns asked alongside these concept questions.

Grokking System Design Fundamentals explains how the same scheduling ideas appear in load balancers and job queues.

TAGS
Coding Interview
System Design Interview
CONTRIBUTOR
Arslan Ahmad
Arslan Ahmad
ex-FAANG engineering manager and author or Grokking series.

GET YOUR FREE

Coding Questions Catalog

Design Gurus Newsletter - Latest from our Blog
Boost your coding skills with our essential coding questions catalog.
Take a step towards a better tech career now!
Explore Answers
When to choose SQL versus NoSQL databases for a design problem
Learn when to choose SQL vs NoSQL in system design interviews. Covers ACID vs BASE, scalability, data models, and real-world examples from Netflix, Uber, and Meta.
How many LeetCode problems should I do per day?
Who owns Atlassian?
What are the types of interview in system analysis and design?
Which skill is required for app development?
What is Big O Notation?
Related Courses
New
Grokking the AI System Design Interview course cover
Grokking the AI System Design Interview
Learn to design AI systems the way interviewers expect: classic ML products, LLM and RAG architectures, and agentic systems, all through the lens of the system design interview.
4.6
(3,192 learners)
Discounted price for Your Region

$99

Grokking the Coding Interview: Patterns for Coding Questions course cover
Grokking the Coding Interview: Patterns for Coding Questions
The 24 essential patterns behind every coding interview question. Available in Java, Python, JavaScript, C++, C#, and Go. The most comprehensive coding interview course with 543 lessons. A smarter alternative to grinding LeetCode.
4.6
Discounted price for Your Region

$197

Grokking Modern AI Fundamentals course cover
Grokking Modern AI Fundamentals
Master the fundamentals of AI today to lead the tech revolution of tomorrow.
4.1
Discounted price for Your Region

$72

Design Gurus logo
One-Stop Portal For Tech Interviews.
Copyright © 2026 Design Gurus, LLC. All rights reserved.