What is process priority and how do nice values work?
The "nice" value (−20 to +19, default 0) hints the scheduler how to share CPU: lower = more CPU priority, higher = "nicer" to others. Only root can go negative.
The counter-intuitive bit is the direction: a higher nice number means lower priority, because the process is being "nicer" and yielding CPU to others. −20 is the greediest, +19 the most self-effacing. Nice values only matter under contention — if the CPU is idle, even a +19 task runs full speed. Start a command niced with nice -n 19 cmd; change a running one with renice. Raising priority (negative values) needs root, since it lets one process starve others.
Nice values:
- Range: -20 (highest priority) to +19 (lowest priority)
- Default: 0
- Only root can set negative nice values
Nice value to priority mapping:
Nice: -20 ... 0 ... +19
High Normal Low priority
Commands:
| Command | Purpose |
|---|---|
nice -n 10 cmd |
Start with nice value 10 |
renice -n 5 -p PID |
Change running process |
ps -o pid,ni,comm |
View nice values |
Examples:
# Run backup with low priority
nice -n 19 tar -czf backup.tar.gz /data
# Increase priority of process (root only)
sudo renice -n -5 -p 12345
# View process priorities
ps -eo pid,ni,comm | head
Real-time vs Normal scheduling:
- Normal: Uses nice values, fair sharing
- Real-time: Strict priority, can starve other processes
Tip: Use nice for CPU-intensive tasks that shouldn't slow down the system.
Go deeper:
nice (Unix) — Wikipedia — the −20…+19 range, why higher = nicer = lower priority, and
renice.