π Linux/Unix: Process Scheduling β nice, renice, chrt Explained with Examples
π§² Introduction β Why Learn Scheduling Commands in Linux?
Linux is a multi-tasking operating system, where multiple processes run concurrently. Sometimes, you need to prioritize or deprioritize processes for optimal performance. Thatβs where nice, renice, and chrt come inβthey control the CPU scheduling priority of processes.
π― In this guide, youβll learn:
- How Linux handles process priorities
- Difference between nice values and real-time priorities
- How to schedule tasks using nice, modify them usingrenice, and apply real-time policies usingchrt
π§ Understanding Scheduling in Linux
- Nice value: Determines priority for non-real-time processes (range: -20[highest] to19[lowest], default is0)
- Real-time priority: Managed by chrt, works with FIFO and RR (Round Robin) policies
| Tool | Affects | Range / Modes | Privilege Required | 
|---|---|---|---|
| nice | New processes | -20to19(default0) | Yes (for -ve) | 
| renice | Running processes | -20to19 | Yes (for others) | 
| chrt | Real-time tasks | FIFO, RR, Other | Yes (root needed) | 
π’ nice β Launch Process with Custom Priority
β Syntax:
nice -n [value] command
π Description:
Runs a command with a custom nice value. Higher value = lower priority.
π§ͺ Example 1: Run with lower priority
nice -n 10 long_running_task.sh
π€ Output: (No output unless the script prints something)
π§ͺ Example 2: Run with higher priority (requires root)
sudo nice -n -5 myscript.sh
π‘ renice β Change Priority of a Running Process
β Syntax:
renice [nice_value] -p [PID]
π Description:
Changes the nice value of an already running process.
π§ͺ Example:
renice 5 -p 1234
π€ Output:
1234 (process ID) old priority 0, new priority 5
π§ Change priority for all userβs processes:
renice 10 -u john
π΄ chrt β Set or View Real-Time Scheduling
β Syntax:
chrt [options] priority command
π Description:
Assigns a real-time scheduling policy (FIFO, RR, OTHER) and priority to a process.
π§ͺ Example 1: Run with FIFO policy
sudo chrt -f 50 ./critical_task
π€ Output: (Runs in real-time FIFO mode at priority 50)
π§ͺ Example 2: Check current scheduling policy
chrt -p 1234
π€ Output:
pid 1234's current scheduling policy: SCHED_OTHER
pid 1234's current scheduling priority: 0
βοΈ Scheduling Use Cases
| Task | Use This Tool | Example | 
|---|---|---|
| Lower priority for backup | nice | nice -n 15 rsync ... | 
| Raise priority for compiler | renice | renice -5 -p 3231 | 
| Real-time video rendering | chrt | chrt -f 80 ./render | 
| Balance multi-user CPU load | renice | renice 10 -u username | 
π Summary β Recap & Next Steps
Linux lets you tune process scheduling to manage system performance and responsiveness. With nice, renice, and chrt, you can control which tasks get CPU time and whenβensuring critical processes run smoothly.
π Key Takeaways:
- nicestarts a command with a custom priority.
- renicechanges priority of already running processes.
- chrtassigns real-time priorities using FIFO/RR policies.
- Lower nice values = higher priority; chrtoffers stricter scheduling.
β FAQs
β Whatβs the default nice value in Linux?
β
 Itβs 0.
β Whatβs the lowest and highest nice value possible?
β
 Highest priority = -20, Lowest priority = 19.
β Can any user lower the nice value (raise priority)?
β No, only root can assign negative nice values.
β What is the difference between nice and chrt?
β
 nice changes user-space CPU priority, while chrt controls real-time scheduling policies.
β How do I check the priority and scheduling policy of a process?
β
 Use:
chrt -p <PID>
Share Now :
