---
title: "Scheduler and task states"
subject: "Embedded System"
chapter: 6
key: "semester_6/embedded_system:scheduler-task-states-role"
source: https://www.bctengineer.com/q/semester_6/embedded_system/scheduler-task-states-role
site: BCT Engineering
---

# Scheduler and task states

Embedded System · Chapter 6: RTOS

- Asked in: 2064 Poush (old course)
- Video: [Introduction to RTOS Part 3 - Task Scheduling | Digi-Key Electronics](https://www.youtube.com/watch?v=95yUbClyf3E) — DigiKey
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_6/embedded_system/scheduler-task-states-role
- Whole chapter: https://www.bctengineer.com/md/semester_6/embedded_system/chapter-6

## Question

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

## 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.

## Answer

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
```text
              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.

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. What does the dispatcher do?
   A. Chooses the scheduling algorithm
   B. Creates the TCB
   C. Performs the context switch handing the CPU to the chosen task
   D. Deletes blocked tasks
   Answer: C. The scheduler decides; the dispatcher actually hands over the CPU. (Key point: Scheduler vs dispatcher)

2. When the awaited event occurs, what does the scheduler do?
   A. Deletes the task
   B. Moves the task to ready and compares its priority with the running task
   C. Leaves it blocked until timeout
   D. Always runs it immediately
   Answer: B. If the woken task has higher priority it pre-empts the running one. (Key point: Blocked to ready)

3. When does the scheduler return a running task to the ready queue?
   A. On pre-emption by a higher-priority task or time-quantum expiry
   B. When it waits for I/O
   C. When it ends
   D. When it is created
   Answer: A. It saves the context and requeues the task. (Key point: Running to ready)

4. Which does the scheduler maintain?
   A. Only the ready queue
   B. Only files
   C. Only interrupts
   D. Ready, wait and delay queues and the TCBs
   Answer: D. It updates queues and TCBs to meet deadlines. (Key point: Queues)

## Related in Embedded System

- [Process vs thread and task states](https://www.bctengineer.com/question.md?key=semester_6%2Fembedded_system%3Aprocess-thread-and-task-states) — Embedded System, chapter 6
- [Different states of a task](https://www.bctengineer.com/question.md?key=semester_6%2Fembedded_system%3Atask-states) — Embedded System, chapter 6

## Related in other subjects

- [Role of curiosity and imagination in invention](https://www.bctengineer.com/question.md?key=semester_5%2Fcommunication_english%3Acuriosity-imagination-observation-scientific-inventions) — Communication English, chapter 2
- [Role of warehouse manager](https://www.bctengineer.com/question.md?key=semester_7%2Fdata_mining%3Awarehouse-manager-role) — Data Mining, chapter 1
