What it does
The nice value decides how much CPU a process gets when the CPU is busy: -20 = highest priority, 19 = lowest, 0 = normal. nice -n 10 CMD starts CMD nicer than normal. Without -n, nice adds 10.
Normal users may only make processes nicer (higher numbers). Negative values need root. To change a running process use renice.
How to write it
nice [-n ADJUSTMENT] [COMMAND [ARGUMENT]...]Options 3
Most used
Nothing matches this filter.
Examples 10
$ run as a normal user# run as root (or with sudo)
1Run a backup with low priority
nice -n 19 tar -czf /tmp/home.tgz /homeUsers and services keep their speed.
2Default adjustment
Without -n: +10.
3Higher priority (root)
nice -n -5 /usr/local/bin/important-jobOnly root may use negative values.
4Normal user tries a negative value
nice -n -5 sleep 1 nice: cannot set niceness: Permission deniedThe command still runs, with nice 0.
5Show the current nice value
nice 0Without a command: print your niceness.
6Low CPU and low disk priority together
nice -n 19 ionice -c3 rsync -a /data/ /backup/data/ionice -c3 = only use the disk when nobody else does.
7Compile without slowing the system
nice -n 15 make -j"$(nproc)"Use all cores, but give way to others.
8Check the NI column in top
Column NI shows the nice value; PR the kernel priority.
9Set the nice value of a service
systemctl edit myappAdd
[Service]andNice=10— services are not started with nice.10Run a cron job nicely
Reports at night with low priority.
Nothing matches this filter.
Watch out
- Nice only matters when the CPU is busy. On an idle CPU every process gets what it wants.
Exit codes
0 | The exit status of the command. |
125 | nice itself failed. |
126 | The command could not be run. |
127 | The command was not found. |