What Is Starvation in Operating Systems?
Learn what starvation is in operating systems, how priority scheduling causes it, how it differs from deadlock, and how aging is used to prevent it.
Expected Interview Answer
Starvation is a condition where a process is perpetually denied the resources it needs to proceed, typically the CPU, because the scheduling policy keeps favoring other processes over it indefinitely.
Starvation commonly arises in priority scheduling, where a steady stream of higher-priority processes keeps arriving, so a low-priority process never gets scheduled even though it is ready to run. It can also occur in Shortest Job First scheduling, where a continuous supply of short jobs keeps pushing a long job to the back of the queue forever. Unlike deadlock, where processes are mutually blocked and none can proceed, starvation lets other processes make progress while one specific process is left waiting indefinitely. The standard fix is aging: gradually increasing the priority of a waiting process the longer it waits, guaranteeing it eventually becomes the highest priority and gets scheduled.
- Understanding starvation helps design fairer schedulers
- Aging guarantees eventual progress for every process
- Distinguishing starvation from deadlock clarifies debugging
- Prevents low-priority work from being indefinitely ignored
- Informs fair lock and queue design beyond just CPU scheduling
AI Mentor Explanation
Starvation is like a net bowler at the academy who never gets a turn because the coach keeps calling in higher-rated bowlers ahead of him every single session. Weeks pass and he is always next in line yet never actually bowls a ball, even though the nets are clearly active and other bowlers are progressing just fine.
Step-by-Step Explanation
Step 1
Resource contention exists
Multiple processes compete for a limited resource, typically CPU time, under some scheduling policy.
Step 2
Policy consistently favors others
A priority or shortest-job-first rule keeps selecting other ready processes over a particular one.
Step 3
The process remains ready but unscheduled
It is never blocked or deadlocked, just perpetually passed over while the system otherwise makes progress.
Step 4
Detect the pattern
Monitoring wait times reveals a process whose wait keeps growing without bound relative to others.
Step 5
Apply aging
The scheduler gradually raises the waiting process's priority over time until it eventually becomes highest and gets scheduled.
What Interviewer Expects
- Defines starvation as indefinite denial of a needed resource
- Distinguishes starvation from deadlock
- Gives a concrete cause (priority or SJF scheduling)
- Names aging as the standard fix
- Can describe how to detect starvation via wait-time monitoring
Common Mistakes
- Confusing starvation with deadlock
- Thinking starvation means the process crashes or errors out
- Forgetting aging as the classic remedy
- Assuming only CPU scheduling can suffer starvation (locks/queues can too)
Best Answer (HR Friendly)
“Starvation happens when a task keeps getting skipped over by a computer's scheduler in favor of other, seemingly more important tasks, so it waits indefinitely even though it's ready to run. The usual fix is to gradually boost a waiting task's priority the longer it waits, so it eventually gets its turn.”
Code Example
def apply_aging(ready_queue, aging_rate=1):
# increase priority of every waiting process each tick
for p in ready_queue:
p['wait_time'] += 1
p['priority'] += aging_rate * p['wait_time']
# pick the highest effective priority to run next
return max(ready_queue, key=lambda p: p['priority'])
queue = [
{'pid': 1, 'priority': 5, 'wait_time': 0},
{'pid': 2, 'priority': 1, 'wait_time': 20}, # long-starved, low base priority
]
next_to_run = apply_aging(queue)
print(next_to_run['pid']) # eventually favors process 2 due to aging
Follow-up Questions
- How does aging technically raise a process's effective priority?
- How does starvation differ from deadlock in terms of system progress?
- Which scheduling algorithms are most prone to starvation?
- Can starvation occur with mutexes or only with CPU scheduling?
- How would you detect starvation in a production system's metrics?
MCQ Practice
1. What best defines starvation?
Starvation means a ready process is indefinitely denied CPU time or another resource because the scheduler keeps favoring others.
2. How does starvation differ from deadlock?
In starvation, the system as a whole keeps progressing while one process waits; in deadlock, the involved processes are mutually stuck.
3. What is the standard fix for starvation in priority scheduling?
Aging gradually raises a waiting process's priority over time, guaranteeing it eventually gets scheduled.
Flash Cards
What is starvation? — A process being perpetually denied a resource it needs, usually CPU time, due to scheduling bias.
How does starvation differ from deadlock? — In starvation the system still progresses; in deadlock, the involved processes are mutually stuck and nothing progresses.
What is the classic fix for starvation? — Aging — gradually increasing a waiting process's priority the longer it waits.
Which algorithms are prone to starvation? — Priority scheduling and Shortest Job First, since both can indefinitely favor certain processes over others.