Skip to content
Tech Interview Prep
Technical interview guide

RTOS & Task Scheduling

How a real-time operating system schedules multiple tasks with timing guarantees, and the classic concurrency hazards (priority inversion, deadlock) that come with it.

Read
60 min
Practice MCQs
25
Interview Q&A
25
Edition
v3
Editorial status
Reviewed

Scope: CMSIS-RTOS2 current API; CMSIS-RTX5 current configuration; current FreeRTOS and Zephyr scheduling guidance reviewed 2026-09-04.

Curated: · Written: · Reviewed:

25 questions

MCQ-1A single-core RTOS runs a preemptive priority scheduler where a higher number means higher priority. At one instant the task table reads: T1 (prio 5) is blocked on a mutex held by T2; T2 (prio 3) is blocked on a UART read; T3 (prio 4) is ready; T4 (prio 2) is ready; T5 (prio 6) has terminated. Which task does the scheduler dispatch next?
MCQ-2A single-core preemptive fixed-priority RTOS runs task L (priority 1), whose job needs 10 ms of CPU. At t = 0 ms, L enters a 4 ms critical section that disables preemption (scheduler lock). At t = 1 ms, task H (priority 3) is released and needs 2 ms of CPU. No other tasks are ready. When does H first execute, and what happens to L's critical section?
MCQ-3A cooperative scheduler runs tasks to completion from a single run queue, in this order: `ble_adv` (1 ms), `key_scan` (0.5 ms), `imu_fusion` (4 ms). `key_scan` empties a 3-deep hardware FIFO that the keypad controller fills at up to 20 presses/s. A new build makes `imu_fusion` busy-wait up to 200 ms for the IMU's data-ready bit. While the IMU is slow, users report that about one in four key presses is ignored. What is the cause?
MCQ-5A 10 ms control loop reads a sensor, runs a fixed-coefficient filter and writes PWM, then ends the iteration with vTaskDelay(pdMS_TO_TICKS(10)). Each job executes in 2 ms. After 500 jobs the sampling instants are 1 s behind the 10 ms slots they were meant to occupy - the 6 s the loop took should have carried about 600 samples, not 500. The filter coefficients assume uniform 10 ms spacing, the job's execution time will not change, and the loop shares the core with higher-priority interrupt-driven work. Which reason makes a delay-until release the right fix?
MCQ-7A single-core RTOS schedules two periodic tasks preemptively, highest priority first, with deadline equal to period and no blocking or release jitter. Task H: period 4 ms, worst-case execution 2 ms, mean execution 0.5 ms. Task L: period 6 ms, worst-case execution 2.5 ms, mean execution 1.0 ms. Means are taken over 10^6 releases. Which statement about Task L's worst-case timing is correct?
MCQ-4On a single-core preemptive fixed-priority system, three independent periodic tasks are all released at t = 0, with deadlines equal to their periods and no blocking or context-switch cost: A (period 10 ms, WCET 3 ms), B (period 20 ms, WCET 5 ms), C (period 50 ms, WCET 10 ms). Priorities were set by business importance, so C runs at the highest priority, B next, and A lowest. What does response-time analysis predict for task A?
MCQ-8A single core runs three periodic tasks under preemptive fixed-priority scheduling, priorities assigned by rate with the shortest period highest, every task's deadline equal to its period, and no locks or other blocking shared between them: - Sensor (highest priority): 1 ms of execution every 4 ms - Control: 2 ms of execution every 9 ms - Logger (lowest priority): 5 ms of execution every 16 ms Average core utilization is 1/4 + 2/9 + 5/16 = 0.785, about 78%, and the team reads the remaining 22% as headroom. What is the Logger's worst-case response time, the longest interval between one of its releases and its completion?
MCQ-6A periodic task τ has worst-case execution time C = 3 ms and period T = 20 ms. One higher-priority task H has C_H = 2 ms and T_H = 10 ms. τ can be blocked for at most B = 4 ms by a lower-priority task holding a shared mutex. Each release of H also adds 0.5 ms of interrupt-handling time on τ's CPU. Using fixed-point response-time analysis, what is τ's worst-case response time?
MCQ-9On a single core with fixed-priority preemptive scheduling, three tasks run: H (priority 3), M (priority 2), L (priority 1). L acquires a plain mutex with no priority inheritance at t = 0 ms and holds it for 4 ms. At t = 1 ms H becomes ready and blocks on that mutex. At t = 2 ms M becomes ready and runs CPU-bound for 20 ms, touching no shared resource. Nothing else runs. How long is H blocked?
MCQ-10A single-core Cortex-M4 runs FreeRTOS with preemptive scheduling. Task L (priority 1) holds a mutex created with xSemaphoreCreateMutex() and has 3 ms of its 4 ms critical section left when task H (priority 5) calls xSemaphoreTake() on that mutex and blocks. Immediately after, task M (priority 3) becomes ready and runs CPU-bound for 30 ms without touching the mutex; no other task is runnable. What is H's blocking time on the mutex?
MCQ-11A FreeRTOS system on a Cortex-M4 runs three tasks: SensorTask (priority 2) holds a lock on the SPI bus for about 3 ms per transfer, ControlTask (priority 6) needs the same bus, and LogTask (priority 4) runs CPU-bound bursts of about 25 ms. The lock is a binary semaphore created with xSemaphoreCreateBinary() and given once at startup. Measured worst-case wait for ControlTask is 28 ms. Changing only the lock to xSemaphoreCreateMutex() drops it to about 3 ms. Why?
MCQ-25A single-core fixed-priority RTOS runs three periodic tasks: H (period 10 ms, execution 2 ms), M (period 20 ms, execution 6 ms), and L (period 50 ms, execution 10 ms). H and L share a mutex. Over a 100 ms trace, H misses its deadline twice. Both misses occur while L holds the mutex and M is runnable; the trace shows H blocked on the mutex, then M executing, then L resuming and releasing the mutex. Total utilization is 0.70. What does this trace establish about the production scheduling invariant?
MCQ-24A 4-core node runs 8 worker threads. p99 request latency rose from 40 ms to 180 ms after a deploy while node CPU utilization stayed at 45%. A trace of one tail request shows: released t=0, first scheduled t=2 ms, blocks on a shared mutex at t=6 ms, wakes at t=151 ms, scheduled again at t=153 ms, completes at t=180 ms. What does the trace establish?
MCQ-12An order service guards three resources with locks: orders, inventory, payments. Four worker threads each hold the lock they already took while acquiring the next: T1 takes orders then inventory; T2 takes inventory then payments; T3 takes payments then orders; T4 takes orders then payments. Under load the service hangs. Which single change removes every circular wait?
MCQ-16A dispatcher runs one consumer thread and one producer thread over a shared `int pending` and a condition variable `cv` guarded by mutex `m`. The consumer executes: ```c if (pending == 0) { pthread_mutex_lock(&m); pthread_cond_wait(&cv, &m); pthread_mutex_unlock(&m); } take_job(); ``` The producer executes: ```c pthread_mutex_lock(&m); pending++; pthread_cond_signal(&cv); pthread_mutex_unlock(&m); ``` After a few thousand jobs the consumer stops taking work; `pending` reads 1 and the consumer is parked in `pthread_cond_wait`. Which change removes the hang?
MCQ-13A pool of five identical worker slots is guarded by a FreeRTOS counting semaphore created with xSemaphoreCreateCounting(5, 5). Three tasks each take one slot with xSemaphoreTake() and hold it. One of those tasks then calls xSemaphoreGive() twice by mistake. What is the semaphore's count, and how many further xSemaphoreTake() calls succeed before one blocks?
MCQ-15A Zephyr worker thread blocks in `k_thread_flags_wait(BIT(0), K_THREAD_FLAGS_ANY_CLEAR, K_FOREVER)`. A UART ISR calls `k_thread_flags_set(worker, BIT(0))` once per received byte. Five bytes arrive back-to-back while the worker is blocked, and the scheduler does not run the worker until all five have been received. The worker's loop body reads exactly one byte from the RX FIFO per wakeup, then calls `k_thread_flags_wait` again. What happens when the worker finally runs?
MCQ-14A FreeRTOS logger on an STM32F4 (configTICK_RATE_HZ = 1000) has a sensor task that posts one 24-byte sample every 1 ms; the sensor task must keep that 1 ms period, and every sample must reach SPI flash. The logger task receives with xQueueReceive and then programs the flash; it already runs above every other application task. Bench measurement: one sample programmed on its own takes 1.5 ms, dominated by the flash page-program cycle, and the CPU is idle during it. With a 16-slot queue the first xQueueSend errQUEUE_FULL appears about 48 ms after boot; with 256 slots, about 0.8 s. Which change lets every sample reach flash without breaking the sensor task's period?
MCQ-17An STM32F4 board (Cortex-M4, 4 priority bits) runs FreeRTOS 10.5 with configMAX_SYSCALL_INTERRUPT_PRIORITY = 5 and configASSERT enabled. The UART RX ISR is registered at NVIC priority 2 and calls xQueueSendFromISR() followed by portYIELD_FROM_ISR(). Under load, configASSERT fires from inside the ISR. Which change removes the assert?
MCQ-18A 7 ms control timer and a 180 ms housekeeping timer are both registered with the same software timer service. The housekeeping callback now copies 4 KB from external flash into RAM, which takes about 3 ms on this board. Instrumentation shows the control callback still executes in 40 us, yet it now enters up to 3 ms late, and each late entry matches the part of the housekeeping copy still running when the control expiry came due. Why is the control callback's entry late?
MCQ-19A driver on a 32-bit tick counter running at 1000 Hz arms a 5000 ms timeout at tick 0xFFFFF000 with `deadline = now + 5000;` and its per-tick check is `if (now > deadline) fire();`. What does the check do?
MCQ-20A Cortex-M4F task's deepest call path has these frames: task entry 48 B, sensor_read 96 B, crc_check 32 B, vendor_flash_write 320 B. The RTOS port pushes 32 B of callee-saved registers onto the task's stack when it switches the task out. A 1 kHz timer interrupt can preempt the task at any instruction; on this core the exception entry frame is 104 B and is pushed onto the stack the task is using. The task is configured with 512 B and hard-faults under load. What is the smallest stack size that cannot overflow?
MCQ-21A FreeRTOS 10.x node on a Cortex-M4 runs vSensorTask (priority 3), which produces 4-byte samples into xSensorQueue (length 8) for vCommsTask (priority 2). ADC_IRQHandler also calls xQueueSendFromISR on that same queue. During shutdown, vShutdownTask waits for vSensorTask to exit (it does, within 5 ms), then calls vQueueDelete(xSensorQueue). 12 ms later the ADC interrupt fires, xQueueSendFromISR runs with the handle it captured at init, and the device hard-faults. What is the correct diagnosis and fix?
MCQ-22A gateway runs a hardware watchdog with a 2 s timeout. A dedicated heartbeat task wakes every 500 ms and feeds it. Three worker tasks (sensor poll, MQTT publish, and flash log writer) each increment a progress counter that the heartbeat task never reads. After a firmware change the gateway stops publishing telemetry, but the watchdog never fires and the device never reboots. Which explanation fits these observations?
MCQ-23A fixed-priority preemptive RTOS runs three periodic tasks on one core: Control (period 10 ms, WCET 3 ms, highest priority, hard real-time), Telemetry (period 20 ms, WCET 4 ms, medium priority, soft real-time), and Logging (period 100 ms, WCET 40 ms, lowest priority, soft real-time). At nominal load the logging response time is 80 ms, inside its 100 ms deadline. A burst doubles the logging input rate, so its effective period becomes 50 ms and total utilization rises to 1.3. Which overload policy should the system apply?