RTOS & Real-Time Concepts · Interview question

What is starvation and how do you prevent it?

A strong answer

Starvation is when a task never gets to run because higher-priority tasks monopolize the CPU. Under preemptive priority scheduling, the highest-priority Ready task always runs, so if a high-priority task stays Ready indefinitely, because it busy-loops, never blocks, or simply has more work than the CPU can do while leaving slack, then every lower-priority task, down to the idle task, is locked out forever. The symptoms are lower-priority work that mysteriously never executes, no low-power idle, and possibly a watchdog that never gets kicked. Prevention is primarily good design: high-priority tasks should do minimal work and then block to wait for their next trigger (a semaphore from an ISR, a queue item, a delay), so they only consume CPU when there's genuinely urgent work, leaving the rest of the time for lower-priority tasks; you also ensure the overall CPU utilization is below 100% with margin so the schedule is feasible (the schedulability concern from the real-time lesson). You assign priorities by deadline urgency rather than importance-in-the-abstract, avoid long computations in high-priority tasks (break them up or move them down), and verify with run-time stats that lower-priority tasks and idle actually run. Note that classic priority scheduling has no built-in anti-starvation aging (unlike some general-purpose OS schedulers), so on an RTOS it's on you to design the workload to be schedulable.

What a weak answer sounds like

You know the answer. Do you know what gets you dinged?

Pro breaks down the answer most candidates actually give to this question — and the specific reason an interviewer marks it down. It’s the difference between sounding correct and sounding senior, on all 472 questions.

From the lesson

Preemptive vs Round-Robin Scheduling

How the scheduler chooses: priority preemption (urgent runs first), round-robin time-slicing among equal priorities, and cooperative scheduling, plus the starvation and fairness tradeoffs.

More Preemptive vs Round-Robin Scheduling questions

Browse all 472 interview questions