Process Priorities: How nice and renice Work
What You Will Achieve
- Explain the relationship between the nice value and the kernel priority (PRI)
- Start a command at low priority with
nice - Change a running process's priority with
renice - Check priority accurately with
top/ps - Answer the exam-frequent "regular users cannot raise priority" with reasoning
This is the core of LPIC-1 objective 103.6 "Modify process execution priorities". It is the technique to run CPU-heavy background work without disturbing interactive work.
Deciding the nice Value
The nice value is an integer from -20 (highest priority) to 19 (lowest priority). The smaller the value, the more CPU the process gets.
| nice value | Priority | Typical use |
|---|---|---|
-20 to -1 |
High (root only) | Work needing real-time responsiveness |
0 |
Standard (default) | Normal commands |
1 to 19 |
Low | Heavy work like backup, batch, build |
If "backup makes interactive work slow", start it at low priority with nice -n 19. A regular user can only change the nice value in the direction of raising it (larger number = lower priority). This is an exam-frequent point.
Steps
Step 1: Check the current nice value
ps -o pid,ni,comm -p $$ nice
PID NI COMMAND 2451 0 bash 0
The NI column is the nice value. nice with no argument shows the current shell's nice value. The default is 0.
Step 2: Start a command at low priority with nice
nice -n 19 tar czf backup.tar.gz /var/www & ps -o pid,ni,comm -C tar
PID NI COMMAND 3120 19 tar
nice -n 19 cmd starts a command with nice value 19 (lowest priority). The work proceeds only when the CPU is idle, minimizing impact on interactive work.
Step 3: Change a running process with renice
renice -n 10 -p 3120 ps -o pid,ni,comm -p 3120
3120 (process ID) old priority 19, new priority 10 PID NI COMMAND 3120 10 tar
renice -n 10 -p PID changes a running process's nice value. -u user changes all of a user's processes and -g group changes per group.
Step 4: Monitor priority with top
top -o NI
PID USER PR NI VIRT RES %CPU COMMAND 3120 user 30 10 118000 4200 2.3 tar 2451 user 20 0 12000 3800 0.1 bash
In top, the NI column is the nice value and PR is the kernel-internal priority, related by PR = 20 + NI (for normal processes). Pressing r inside top allows interactive renice.
Step 5: Confirm the regular-user constraint
renice -n -5 -p 3120 sudo renice -n -5 -p 3120
renice: failed to set priority for 3120 (process ID): Permission denied 3120 (process ID) old priority 10, new priority -5
A regular user cannot set a negative (high priority) nice value and gets Permission denied. Raising priority requires root privileges (sudo).
Why Regular Users Cannot Raise Priority
Making the nice value negative lets that process preferentially seize CPU over other users' processes. If anyone could freely raise priority, a malicious user or a buggy program could monopolize the entire system, collapsing fairness in a multi-user environment. So Linux adopts an asymmetric permission design: "lowering priority (yielding) is allowed for everyone, raising priority (seizing) is root-only".
The word nice comes from "being nice to other processes by yielding CPU". Raising the value from the default 0 means "yielding more nicely" = lower priority. Grasping this direction prevents confusion over the sign of the nice value. Note that nice is only a hint to the scheduler; if the CPU is idle, even a high-nice-value process proceeds.
Troubleshooting
Symptom: renice gives Permission denied
Cause: A regular user is trying to lower the nice value (negative direction), or change someone else's process
Check:
ps -o pid,user,ni -p PID
Fix: Use sudo renice to raise priority. Changing another user's process also requires root privileges.
Symptom: Work does not slow down even at nice -n 19
Cause: nice is a relative hint; with no competing processes it can use full CPU
Check:
top -o %CPU
Fix: It is normal behavior that nice takes effect only under CPU contention. To lower I/O priority, use ionice separately.
Symptom: A background build makes interactive work slow
Cause: The build process competes for CPU equally at the default nice value 0
Check:
ps -o pid,ni,comm -C make
Fix: Lower the running process to the lowest priority with renice -n 19 -p PID. From now on, start it with nice -n 19 make.
Completion Checklist
- [ ] Checked the current nice value with
ps -o pid,ni,comm - [ ] Started at low priority with
nice -n 19 - [ ] Changed a running process with
renice -n -p PID - [ ] Monitored priority in the
topNI column - [ ] Confirmed the constraint that regular users cannot raise priority
Summary
| Scenario | Command | Purpose |
|---|---|---|
| At start | nice -n 19 cmd |
Start heavy work at low priority |
| While running | renice -n 10 -p PID |
Adjust a running process |
| Per user | renice -n 5 -u user |
Change all processes at once |
| Check | ps -el / top |
Monitor NI / PRI |
| Raise priority | sudo renice -n -5 |
Root only |
Process priority is the basis of CPU resource management. After covering the LPIC-1 process management area, combine it with shell environment and link mechanisms to complete your operational knowledge.