Skip to main content

Scheduler and task states

Short answer

A scheduler is the kernel module that selects the next task to run. It manages task states by moving tasks between new, ready, running, blocked, and terminated states according to events like dispatch, preemption, I/O waits, and completion.

What is a scheduler? Describe its role in managing task states in detail.

A scheduler is the kernel module that decides which ready task gets the CPU, when to switch tasks and for how long, according to a scheduling algorithm (priority-based pre-emptive, round robin, RMS, EDF). The part that actually hands over the CPU is the dispatcher.

Task states

              admit                dispatch
   [New] ------------> [Ready] <------------> [Running]
                          ^   pre-empt/time out   |
                          |                       | wait
                    event occurs                  v
                          +------------------ [Blocked]
   [Running] --exit--> [Terminated]

Role of the scheduler in managing the states

  1. New to Ready: when a task is created, the scheduler places it in the ready queue (TCB state = Ready).
  2. Ready to Running (dispatch): at each scheduling point the scheduler picks the highest-priority ready task (or the next in the queue) and the dispatcher performs a context switch to run it.
  3. Running to Ready (pre-emption / time-slice end): when a higher-priority task becomes ready or the time quantum expires, the scheduler saves the context and returns the running task to the ready queue.
  4. Running to Blocked: when a task waits for I/O, a semaphore or a delay, the scheduler moves it to the blocked (waiting) queue and selects another task.
  5. Blocked to Ready: when the awaited event occurs (interrupt, signal, timeout), the scheduler moves the task back to the ready queue and compares its priority with the running task (pre-empting if higher).
  6. Running to Terminated: when the task ends, resources are released and the scheduler selects the next task.

It also maintains the ready, wait and delay queues, updates the TCBs, and ensures that deadlines are met and no task starves.

✓ Answer checked by Claude Opus 5.5 (high effort)

All Embedded System chapter 6 questions →