Many processes want the CPU at once, and the kernel's scheduler shares it out. Niceness is a hint you can give it about a normal process.
The scale
Niceness runs from -20 to 19. The default is usually 0.
- A higher number means "nicer" to others: the process gets a smaller share when the CPU is contested.
- A lower (negative) number means it gets a larger share.
Niceness matters mainly when processes compete. On an idle machine, a process with niceness 19 can still use a whole core. It is not a cap on CPU, memory or disk use.
Starting with a niceness
$ nice
0
$ nice -n 10 nice
10nice on its own prints the current niceness. nice -n 10 command runs the command with 10 added to it. If you leave out -n, the adjustment is 10. A typical use is a large compression job that should not slow your other work:
nice -n 19 tar -czf backup.tar.gz projects/Changing a running process
Use renice:
$ sleep 600 &
[1] 5100
$ renice -n 5 -p 5100
5100 (process ID) old priority 0, new priority 5
$ ps -o pid,ni,comm -p 5100
PID NI COMMAND
5100 5 sleepThe NI column shows niceness. With the usual Linux renice, the number after -n is the new value itself, not an amount to add. This differs from nice, and some other systems treat it as an increment. You can also target all of a user's processes with -u username.
Who may lower it
Ordinary users can make their processes nicer. Lowering the number, which raises priority, normally needs root:
$ renice -n -5 -p 5100
renice: failed to set priority for 5100 (process ID): Permission denied
$ sudo renice -n -5 -p 5100
5100 (process ID) old priority 5, new priority -5Administrators can relax this with resource limits (ulimit -e), so some systems allow a little more.
In top, the NI column shows niceness and PR shows the kernel-based priority. Some desktop systems group processes per session, which can weaken the effect of niceness between different terminals.
Try it
Start nice -n 15 sleep 300 & and check it with ps -o pid,ni,comm. Then raise its niceness to 19 with renice, and try to bring it back down. The processes and cron lab is a safe place for this.
Check your understanding
Niceness and priority
All 4 sections ยท no timer
Unlimited retries
Questions from every section are combined into one assessment. Answer them all correctly to complete the article.
Your completion saves in this browser. Sign in to sync it to your account.