Why One Process Never Gets CPU Time on a Two-Core System
System DesignModel answerLast updated
Given five identical CPU-bound processes on two cores where four run fairly and one runs never, pinpoint which OS subsystem is responsible and explain what can go wrong there.
Background
A developer notices something odd on a two-core machine running five identical, CPU-bound worker processes. Monitoring shows that four of the five workers share the two cores evenly — each gets roughly the same amount of CPU time. The fifth worker, however, shows zero CPU usage over an extended observation window. It is not crashing: it exists in the process table and has not exited.
Your Task
-
Identify the OS component you would examine first to explain this behavior, and justify why that component — rather than memory management, the file system, or device drivers — is responsible for the outcome.
-
List the specific conditions within that component that could cause exactly this symptom: four processes sharing CPU fairly while a fifth is permanently excluded.
-
Distinguish between the case where the fifth process is runnable but never chosen versus the case where it is not runnable at all. Explain how you would tell the difference at runtime and what each case implies for the fix.
-
Propose concrete remedies for each root cause you identify.
-
Support your reasoning with a short simulation (code optional but encouraged) that reproduces the symptom and demonstrates how a fix restores fair scheduling.
What a complete answer looks like
- Names the right component immediately and explains the reasoning in one or two sentences.
- Covers at least four distinct failure modes within that component.
- Mentions at least one diagnostic command or metric for each failure mode.
- Describes the concept of aging and why it matters.
- Includes working code (any language) that models strict-priority starvation and shows it disappearing when the scheduler policy changes.
Hints
Hint 1
Think about which part of the OS actually decides, tick by tick, which process occupies a core. Memory management and I/O subsystems don't make that call.
Hint 2
The four processes sharing time evenly is a clue: something is consistently ranking the fifth process lower. What properties attached to a process control that ranking?
Hint 3
Before assuming the scheduler is skipping the process unfairly, check whether the process is even eligible to run. A process blocked on a lock or I/O never reaches the run queue in the first place — and the fix is completely different.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
The component to examine: the CPU scheduler
The CPU scheduler — specifically the short-term scheduler, its per-core run queues, and the dispatcher — is the right place to look. It is the only OS component that decides which ready process occupies a core at each scheduling event. Memory management, the file system, and device drivers influence throughput and latency, but none of them determine who gets CPU time. When four identical processes share two cores evenly and a fifth gets nothing, the cause is a scheduling decision that systematically excludes the fifth process.
The phenomenon has a name: starvation. A process is starved when it is ready to run but never selected because other processes always outrank it.
Failure modes that produce this exact symptom
1. Strict priority scheduling without aging
This is the most common cause. If the fifth process has a lower priority than the other four — even by a small amount — and the scheduler always picks the N highest-priority runnable processes (where N equals the number of cores), the fifth process never wins. The four higher-priority processes are always runnable and always fill both cores.
On Linux, the relevant knobs are the nice value (-20 to +19) and the real-time priority set via chrt. Check with:
ps -eo pid,ni,pri,stat,comm
chrt -p <pid>
The fix is to normalize priorities across the five processes. The deeper fix is aging: incrementally raise a process's effective priority the longer it has been waiting. Once the accumulated wait credit exceeds the priority gap, the process gets scheduled.
2. Real-time scheduling class mismatch
If the four active processes run under SCHED_FIFO or SCHED_RR and the fifth runs under SCHED_OTHER (the default time-sharing class), the real-time tasks will always preempt the normal task. With four CPU-bound real-time tasks and only two cores, the SCHED_OTHER process never sees the CPU.
Diagnose with chrt -p <pid>. Fix by either moving the fifth process to the same scheduling class or capping the real-time processes with sched_rt_runtime_us.
3. CPU affinity pinning to an unavailable core
taskset or sched_setaffinity can restrict a process to a specific CPU. If that CPU is offline, isolated via isolcpus, or simply never hosting the process's run queue, the process stays queued but never dispatched.
taskset -p <pid> # shows the allowed CPU mask
cat /sys/devices/system/cpu/cpu*/online
Fix by widening the affinity mask to include active cores.
4. cgroup CPU quota exhaustion
A cgroup cpu.max or cpu.cfs_quota_us value set to zero or a very small number will throttle the process to nothing even if the scheduler would otherwise pick it. The scheduler's accounting marks the process as permanently throttled.
cat /sys/fs/cgroup/.../cpu.max
cat /sys/fs/cgroup/.../cpu.stat # look at nr_throttled
Fix by raising or removing the quota.
5. Virtual runtime corruption in CFS
Linux's Completely Fair Scheduler orders tasks by vruntime — lower value runs next. If a process's vruntime is far ahead of the others (due to a bookkeeping bug or an unusual sleep/wake pattern), it appears "overscheduled" and is never the most deserving task. This is rare but worth checking if the other causes are ruled out.
Runnable vs. not runnable: the critical distinction
Before concluding the scheduler is misbehaving, check whether the process is actually in the ready state.
Process state (ps column S) | Meaning | Fix lives in |
|---|---|---|
R | Running or on the run queue | Scheduler policy |
S | Interruptible sleep (waiting on I/O, signal, lock) | Synchronization / I/O layer |
D | Uninterruptible sleep (usually blocked on disk I/O) | Block layer / storage driver |
If the process shows S or D, the scheduler is behaving correctly — it cannot run a process that is blocked. The real bug is a lost wakeup, a deadlock, or a blocking syscall that never returns. Fix the synchronization issue, not the scheduler.
Simulation
The code below models a priority scheduler on cores CPUs. With aging=0, a single lower-priority process is permanently starved. Turning on aging lets its effective priority catch up.
from typing import List
def simulate(
priorities: List[int],
cores: int,
ticks: int,
aging: float = 0.0,
) -> List[int]:
"""
Priority scheduler simulation over `ticks` time slices.
Higher value = higher priority.
Effective priority = base + aging * ticks_waited.
Ties broken by longest wait, then lowest index (round-robin).
Returns CPU slices received by each process.
"""
n = len(priorities)
cpu_time = [0] * n
waited = [0] * n
for _ in range(ticks):
order = sorted(
range(n),
key=lambda p: (-(priorities[p] + aging * waited[p]), -waited[p], p),
)
running = set(order[:cores])
for p in range(n):
if p in running:
cpu_time[p] += 1
waited[p] = 0
else:
waited[p] += 1
return cpu_time
if __name__ == "__main__":
prios = [10, 10, 10, 10, 5] # fifth process has a lower priority
# Strict priority — fifth process is starved
print(simulate(prios, cores=2, ticks=1000))
# → [500, 500, 500, 500, 0]
# Aging enabled — fifth process now gets CPU time
print(simulate(prios, cores=2, ticks=1000, aging=1.0))
# → roughly equal distribution
# All equal priorities — fair round-robin, no starvation
print(simulate([10] * 5, cores=2, ticks=1000))
# → [400, 400, 400, 400, 400]
With strict priority, four processes share 2,000 core-slices (500 each) and the fifth receives 0 — exactly the reported symptom. With equal priorities and round-robin tie-breaking, each process gets its fair share of 400 slices (2 cores × 1,000 ticks ÷ 5 processes). Aging closes the gap: once the fifth process's accumulated wait credit exceeds the priority difference of 5, it starts winning scheduling decisions.
Complexity: O(T · n log n) for T ticks and n processes, since the ready set is sorted each tick. Real schedulers use a red-black tree (CFS) or per-priority bitmap queues for O(log n) or O(1) per decision.
Common mistakes
- Blaming the wrong component. Memory management and I/O subsystems are often cited first. Neither decides which process runs on a core.
- Skipping the runnable check. Jumping straight to scheduler tuning without confirming the process is in state
Rwastes time and may miss a deadlock. - Ignoring affinity and cgroups. In containerized or cloud environments, these are more likely culprits than
nicevalues. - Proposing only a symptom fix. Raising the priority of the fifth process might work today but does not prevent the same problem from recurring. Adding aging or switching to a fair-share policy (CFS with equal weights) is the durable solution.