DEV Community

Cover image for Linux Process Priorities: Understanding `nice` and `renice`
Hosni Zaaraoui
Hosni Zaaraoui

Posted on

Linux Process Priorities: Understanding `nice` and `renice`

Ever wondered how Linux decides which process gets more CPU time?

Linux uses a value called the nice value to influence process scheduling.
Every process has a nice value ranging from -20 to 19.

📌 Key points:
✅ Lower nice value = Higher CPU priority
✅ Higher nice value = Lower CPU priority

Examples:

  • -20 → Highest priority
  • 0 → Default priority
  • 19 → Lowest priority

Running a command with a custom nice value

nice -n +5 updatedb &
Enter fullscreen mode Exit fullscreen mode

This starts the updatedb process in the background with a nice value of 5, making it "nicer" to other processes by giving them more CPU access.

You can verify it using:

top
Enter fullscreen mode Exit fullscreen mode

Look for the NI (Nice) column.

Changing the priority of a running process

renice -n -5 20284
Enter fullscreen mode Exit fullscreen mode

This changes the nice value of process 20284 to -5, giving it a higher CPU priority.

Important Rules

🔹 Regular users can only set nice values between 0 and 19
🔹 Regular users can only modify their own processes
🔹 Regular users can increase the nice value (lower priority) but cannot decrease it later
🔹 Only the root user can assign negative nice values or freely increase/decrease priorities

Understanding nice and renice is useful when managing resource-intensive tasks, background jobs, and production Linux systems.

📚 Credit: Linux Bible by Christopher Negus

Top comments (0)