βš™οΈ Linux/Unix: Process & Job Control
Estimated reading: 3 minutes 50 views

πŸ•’ 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 using renice, and apply real-time policies using chrt

🧠 Understanding Scheduling in Linux

  • Nice value: Determines priority for non-real-time processes (range: -20 [highest] to 19 [lowest], default is 0)
  • Real-time priority: Managed by chrt, works with FIFO and RR (Round Robin) policies
ToolAffectsRange / ModesPrivilege Required
niceNew processes-20 to 19 (default 0)Yes (for -ve)
reniceRunning processes-20 to 19Yes (for others)
chrtReal-time tasksFIFO, RR, OtherYes (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

TaskUse This ToolExample
Lower priority for backupnicenice -n 15 rsync ...
Raise priority for compilerrenicerenice -5 -p 3231
Real-time video renderingchrtchrt -f 80 ./render
Balance multi-user CPU loadrenicerenice 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:

  • nice starts a command with a custom priority.
  • renice changes priority of already running processes.
  • chrt assigns real-time priorities using FIFO/RR policies.
  • Lower nice values = higher priority; chrt offers 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 :

Leave a Reply

Your email address will not be published. Required fields are marked *

Share

πŸ”΅ Linux/Unix: Scheduling (nice, renice, chrt)

Or Copy Link

CONTENTS
Scroll to Top