Priorities — nice and renice
Two programs want the CPU: who gets it? The kernel shares it out by niceness, from -20 (first in line) to 19 (gives way to everyone). Almost everything runs at 0.
Something is eating a whole CPU right now:
top
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
3412 student 20 0 7880 2140 1284 R 98.7 0.1 6:41.00 gzip
NI is its niceness; PR the priority the kernel works with (20 + NI).
ps -o: the columns you want
ps -o pid,ni,%cpu,comm -p 3412
PID NI %CPU COMMAND
3412 0 98.7 gzip
-o picks the columns: pid, user, ni, %cpu, %mem, rss, etime, cmd… -p the process.
renice: a process that runs
That gzip packs old photos — it can wait. Make it nicer:
renice -n 10 -p 3412
3412 (process ID) old priority 0, new priority 10
When nothing else wants the CPU it runs as fast as before; it only lets the web server go first.
| Who | May |
|---|---|
| any user | make their own processes nicer (a higher number) |
| root | anything — also lower the number, below 0 |
Going back from 10 to 0 is "less nice" — only root may: renice -n 0 -p 3412 → Permission denied.
nice: start it nice
nice -n 19 tar -czf ~/docs.tar.gz ~/documents
Runs the command at niceness 19. nice alone prints the niceness you run at: 0.
💡 For a job that runs every night (backups, reports):
nice -n 10in front of it in the crontab, orNice=10in its systemd unit.