In this lesson, you will learn how Linux distinguishes between "fair" task execution and the strict, deterministic requirements of real-time processes.
The Problem with "Fairness"
Up until now, you have worked with standard processes managed by the Completely Fair Scheduler (CFS). In a standard system, the kernel tries to be "fair" to every process, giving each a slice of CPU time based on its nice value. While this keeps a desktop responsive, it is non-deterministic. If a heavy background task suddenly demands CPU cycles, your foreground task might be delayed by a few milliseconds—a phenomenon known as "scheduling latency."
Introducing Real-Time Scheduling
Real-time scheduling classes (SCHED_FIFO and SCHED_RR) exist to bypass the "fairness" logic entirely. When you assign a process to a real-time class, you are telling the kernel: "This process is more important than anything else."
- Deterministic Behavior: A real-time process will preempt any standard process immediately. The kernel does not care about "fairness" here; it only cares that the real-time task executes the moment it is ready.
- The Priority Shift: In standard scheduling, higher
nicevalues mean lower priority. In real-time scheduling, we use a static priority range (1 to 99). A real-time process with a priority of 99 will always run before a process with a priority of 1, regardless of how much CPU the other processes have consumed.
Illustration: The Priority Hierarchy
Imagine the scheduler as a line at a store.
- Standard Processes: Stand in a long, shifting line where the cashier tries to be "fair" by serving everyone a little bit.
- Real-Time Processes: These are like VIPs who walk straight to the front of the line. As long as a VIP is waiting, the cashier (the CPU) will never serve the people in the standard line.
If you create a real-time process that enters an infinite loop, it can effectively freeze your entire system because it refuses to yield the CPU to the standard processes that handle your shell or desktop environment.
Key Takeaway: While standard scheduling prioritizes balanced system throughput, real-time scheduling provides deterministic, high-priority execution by forcing the kernel to bypass fair-share rules.