OS//real-time operating system

A real-time operating system (RTOS) is an operating system whose scheduler and services have bounded, predictable latencies, so that the most urgent task always gets the processor within a known time, and it is what runs the control software of autopilots, drives, medical devices and car ECUs. A general-purpose OS optimizes throughput and fairness on average; an RTOS gives up some of both to guarantee the worst case.


A real-time operating system (RTOS) is an operating system whose scheduler and services have bounded, predictable latencies, so that the most urgent task always gets the processor within a known time, and it is what runs the control software of autopilots, drives, medical devices and car ECUs. A general-purpose OS optimizes throughput and fairness on average; an RTOS gives up some of both to guarantee the worst case.

It offers a small set of mechanisms. Preemption by priority: when a higher-priority task becomes ready, it interrupts the running lower one at once, not at the end of a time slice. Bounded interrupt and context-switch latencies, documented and testable. Timers that release periodic tasks on time. Mutexes with priority inheritance, so that a shared resource cannot cause unbounded priority inversion. Queues and semaphores to pass data between tasks and interrupt handlers without hidden blocking.

On microcontrollers the common ones are FreeRTOS, Zephyr, NuttX and ChibiOS; PX4 runs on NuttX and ArduPilot on ChibiOS (autopilot). Large and certified systems use commercial kernels such as VxWorks or QNX, which come with the evidence that functional safety standards demand.

Linux can be made much closer to real time. The PREEMPT_RT patch set, in the mainline kernel since version 6.12, makes most of the kernel preemptible and brings typical scheduling latency from milliseconds to tens of microseconds; an industrial PC coordinating EtherCAT axes at 1 kHz relies on it. Bounding its worst case is still harder than on a small RTOS, because drivers and the rest of the stack are vastly larger.

An RTOS does not make code real time by itself. A task that allocates memory in its loop, waits on a blocking SD write or runs a garbage-collected language inherits those delays; the RTOS guarantees when a task starts, not how long it runs (worst-case execution time).

The alternative at the simple end is bare metal: a timer interrupt and a main loop, or a cyclic executive. An RTOS pays for itself once several loops at different rates, communications and logging share one chip (real-time computing).