nice and renice Commands in Linux: Set Process Priority

By 

Published on

8 min read

CPU tile beside a nice-value slider ranging from -20 to 19

When you run a CPU-heavy task on a shared server, a long compile job or a background backup can slow down everything else. Linux lets you give that process a lower priority, so it receives a smaller share of CPU time when it competes with other work. Use nice to adjust the priority when you start a command and renice to change the priority of a process that is already running.

This guide explains how nice values work in Linux and how to use nice and renice to start and adjust processes at different priority levels.

How Nice Values Work

For processes using normal time-sharing or batch scheduling, the kernel uses a nice value to decide how much CPU time they should receive relative to competing processes. The range goes from -20 (highest priority) to 19 (lowest priority). New processes inherit their parent’s nice value, which is usually 0.

A higher nice value means the process is “nicer” to other work and receives a smaller CPU share under contention. A lower nice value gives it a larger share. Without contention, even a process at nice 19 can use a full CPU core. Niceness does not set a CPU usage limit.

On most systems, regular users can only increase the nice value of their own processes (lower their priority). Decreasing the value normally requires root privileges, even when changing it from 10 back to 0. An administrator can allow exceptions through the RLIMIT_NICE resource limit.

You can check the current nice value of a process in the NI column of ps or top :

Terminal
ps -eo pid,ni,comm

For example, the output may look like this:

output
    PID  NI COMMAND
      1   0 systemd
    842   0 sshd
   1024  10 rsync

The rsync process in the example above is running with a nice value of 10, which is lower priority than the default.

nice Command Syntax

The nice command runs a command with an adjustment to the inherited nice value:

txt
nice [OPTION] [COMMAND [ARGS]...]

With no command, nice prints its current nice value, inherited from your shell:

Terminal
nice

In a shell with the usual nice value of 0, the output is:

output
0

This does not change the shell’s priority. When you pass a command, nice adds 10 to the inherited nice value unless you choose a different adjustment with -n.

The examples below assume a starting nice value of 0 and use GNU nice from coreutils and renice from util-linux, the implementations commonly found on Linux.

Running a Command With Lower Priority

To try the default adjustment without creating files or running a heavy workload, use nice to run another copy of itself:

Terminal
nice nice

The second nice prints the adjusted value:

output
10

The outer command adds 10 to the inherited value of 0. The inner command only prints that value and exits.

For a practical example, you can run an archive job at a lower CPU priority. Choose an unused archive filename and replace /var/www with a directory you can read:

Terminal
nice tar -czf backup.tar.gz /var/www

The tar process runs with a nice value of 10 instead of 0. This can help interactive programs stay responsive when they compete with the archive job for CPU time.

You can choose a different adjustment with the -n option. For example, to add 15 when running an existing build script:

Terminal
nice -n 15 ./build.sh

From a starting value of 0, the build script runs at nice 15. If your shell already has a nice value of 10, the result is 19, the maximum allowed value, rather than 15.

Running a Command With Higher Priority

To raise a command’s priority, use a negative adjustment. This normally requires root privileges. For example, a regular user without a suitable nice resource limit can try:

Terminal
nice -n -5 nice

From a starting value of 0, GNU nice reports the failed adjustment and the inner command prints the unchanged value:

output
nice: cannot set niceness: Permission denied
0

GNU nice still runs the command after this permission error, so the warning does not mean the workload was stopped.

With sudo , you can normally apply the adjustment:

Terminal
sudo nice -n -5 nice

When the starting value is 0, the inner command prints:

output
-5

This command runs as root. To raise the priority of a job you already started as your own user, use sudo renice as shown below. Changing its nice value does not change its owner.

Use negative values carefully. A CPU-heavy process at nice -20 can leave competing work with little CPU time.

renice Command Syntax

The renice command changes the nice value of a process that is already running:

txt
renice PRIORITY [-p|-g|-u] IDENTIFIER...

By default, renice interprets the identifier as a process ID. The -p option makes that explicit, -g targets a process group, and -u targets processes owned by a given user.

Unlike nice -n, the priority in this form is an absolute nice value. For example, renice 10 -p PID sets the value to 10; it does not add 10.

In util-linux, renice -n 10 also sets an absolute value by default, but it becomes a relative adjustment when the POSIXLY_CORRECT environment variable is set. We use the form without -n to keep the examples unambiguous. See the renice manual for details.

Changing the Priority of a Running Process

To lower the priority of a running process, find its PID with ps or pgrep , then pass it to renice. Replace 4821 with the PID of your process:

Terminal
renice 10 -p 4821

If the process starts at nice 0, the output is:

output
4821 (process ID) old priority 0, new priority 10

The output confirms the change from 0 to 10.

To try this on a harmless process, start sleep in the background, capture its PID, and change its nice value:

Terminal
sleep 60 &
job_pid=$!
renice 10 -p "$job_pid"
ps -p "$job_pid" -o pid,ni,comm

$! holds the PID of the last background job. The NI column from ps should show 10. The process exits on its own after 60 seconds, so run the following examples before it finishes.

To change the value again, pass the new absolute value:

Terminal
renice 15 -p "$job_pid"

This changes the nice value from 10 to 15, rather than adding 15 to it.

Restoring the value to 0 raises the process’s priority and normally requires sudo:

Terminal
sudo renice 0 -p "$job_pid"

On Linux, nice values are per thread. Renicing a PID does not automatically update every worker thread or an existing child process. Newly created children inherit the calling thread’s nice value.

Renicing All Processes for a User

To adjust the current processes owned by a user, pass the username with -u. For example, if your backup jobs run under an account named backup:

Terminal
sudo renice 15 -u backup

This sets the account’s current processes to nice 15. It does not configure a permanent default for the account or change jobs that will start independently later.

Renicing a Process Group

To target a process group, use -g with the process group ID (PGID). First, list process IDs and their groups:

Terminal
ps -eo pid,pgid,ni,comm

If the jobs you want to adjust belong to group 1820, set their nice value to 5:

Terminal
sudo renice 5 -g 1820

Replace 1820 with the PGID you found. A process group can contain several commands from the same job, such as the stages of a shell pipeline.

Quick Reference

TaskCommand
Show the nice value inherited from your shellnice
Add 10 when starting a commandnice command
Add 15 when starting a commandnice -n 15 command
Subtract 5 when starting a command as rootsudo nice -n -5 command
Set a running process to nice 10renice 10 -p PID
Restore a running process to nice 0sudo renice 0 -p PID
Set a user’s current processes to nice 15sudo renice 15 -u USER
Set processes in a group to nice 5sudo renice 5 -g PGID

Troubleshooting

nice: cannot set niceness: Permission denied
You tried to apply a negative adjustment without permission to raise priority. Use sudo when appropriate, or choose a nonnegative adjustment. GNU nice still runs the command at its inherited nice value after this warning.

renice reports permission denied or operation not permitted
You tried to change a process you do not own, or to decrease a nice value without the required privileges. On most systems, even restoring your own process from nice 10 to 0 requires sudo.

renice reports no such process
The process has exited or the PID is wrong. Find the current PID with ps or pgrep and try again. In the sleep example above, the process disappears after 60 seconds.

Nice value does not seem to affect performance
Nice values matter when processes compete for CPU time. On an idle system, a niced process can still use a full CPU core. Use htop to check whether the workload is CPU-bound.

Autogrouping and cgroup CPU scheduling also affect how CPU time is shared. With autogrouping enabled, changing niceness in one terminal session may have little effect on a job in another session. Process nice values apply within the same scheduling group; see the Linux scheduling documentation for the details.

A backup still slows down disk access
nice and renice adjust CPU scheduling, so they do not directly set disk I/O priority. Some I/O schedulers derive a default I/O priority from CPU niceness, but the behavior depends on the scheduler. Use ionice when you need to set I/O priority explicitly, and check whether your active I/O scheduler supports it.

Conclusion

For a long job that can wait, start with the default nice adjustment and check its NI value with ps. If you prefer to adjust priorities interactively, see how to change nice values in htop .

Linuxize Weekly Newsletter

A quick weekly roundup of new tutorials, news, and tips.

About the authors

Dejan Panovski

Dejan Panovski

Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 1000+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.

View author page