chrt
Set real-time scheduling attributes of processes
TLDR
Display attributes of a process
Display attributes of all threads of a process
Display the min/max priority values that can be used with chrt
Set the scheduling priority of a process
Set the scheduling policy of a process
SYNOPSIS
chrt [options] [priority] command [arguments...]
chrt [options] -p PID
PARAMETERS
-p, --pid
Operate on an existing process identified by its Process ID (PID) instead of starting a new command. When used, the command and arguments should be omitted.
-f, --fifo
Set the scheduling policy to SCHED_FIFO (First-In, First-Out). This policy does not use time slicing; a process runs until it yields or blocks.
-r, --rr
Set the scheduling policy to SCHED_RR (Round-Robin). This policy uses a time quantum for fair distribution among processes of the same priority.
-o, --other
Set the scheduling policy to SCHED_OTHER (default time-sharing). Real-time priority is ignored; nice value applies.
-b, --batch
Set the scheduling policy to SCHED_BATCH, intended for CPU-bound batch jobs that should run at a lower priority than SCHED_OTHER processes.
-i, --idle
Set the scheduling policy to SCHED_IDLE, for very low priority tasks that run only when no other process is runnable on the CPU.
-a, --all-tasks
When operating on an existing PID, apply the scheduling changes to all tasks (threads) belonging to that process.
-m, --max
Display the maximum valid real-time priority (typically 99) supported by the system for SCHED_FIFO and SCHED_RR policies.
-v, --version
Display version information and exit.
-h, --help
Display a help message and exit.
DESCRIPTION
chrt is a command-line utility used to examine and change the real-time scheduling attributes of a process or a command. In Linux, real-time scheduling policies (SCHED_FIFO and SCHED_RR) are distinct from the default time-sharing policy (SCHED_OTHER). They are crucial for applications requiring predictable and low-latency execution, such as audio processing, robotics, or industrial control systems, where timely responses are critical.
SCHED_FIFO (First-In, First-Out) ensures that a process runs until it voluntarily yields the CPU, blocks, or is preempted by a higher-priority SCHED_FIFO or SCHED_RR process. It does not allow time slicing. SCHED_RR (Round-Robin) is similar to SCHED_FIFO but includes a time quantum; if a process of the same priority is ready to run and its quantum expires, it will yield the CPU and be moved to the end of the run queue.
chrt allows users to query the current policy and priority of an existing process by its PID or to launch a new command with specific real-time scheduling parameters. Real-time priorities typically range from 1 (lowest real-time) to 99 (highest real-time), with higher numbers indicating greater priority. This is separate from nice values, which affect the SCHED_OTHER policy.
CAVEATS
Modifying real-time scheduling attributes typically requires elevated privileges (e.g., root access or the CAP_SYS_NICE capability) to prevent system instability. Misuse of real-time scheduling can lead to processes monopolizing the CPU, potentially causing system unresponsiveness or starvation of critical services if not managed carefully.
REAL-TIME PRIORITY RANGE
For SCHED_FIFO and SCHED_RR policies, real-time priorities typically range from 1 to 99, where 99 is the highest priority. Lower values indicate lower real-time priority. You can query the maximum supported real-time priority using the -m option.
DEFAULT POLICY WHEN RUNNING A COMMAND
When launching a new command without explicitly specifying a policy flag (e.g., -f or -r): if a priority is provided, chrt defaults to SCHED_RR. If no priority is given, the command runs with the default SCHED_OTHER policy.
HISTORY
chrt is part of the util-linux package, a collection of essential system utilities for Linux. Its development is closely tied to the evolution of real-time capabilities within the Linux kernel, providing a user-space interface to the kernel's real-time scheduling policies. The demand for such a tool arose with the increasing use of Linux in time-critical applications, where precise control over process execution is paramount. It serves as a fundamental utility for configuring applications for predictable behavior on Linux systems.