VMware ESXi and vSphere Cluster Management

Change Process Priority with nice and renice in Linux

Learn how Linux nice and renice values affect CPU scheduling, how to inspect NI values, change running processes, handle permissions, and troubleshoot priority changes.

What process priority means in Linux

A process is a running instance of a program. The Linux kernel's scheduler chooses which runnable processes receive CPU time. Priority-related values influence that choice when several processes compete for the CPU.

A nice value is a user-facing adjustment to a process's ordinary CPU scheduling preference. It is not a guarantee that a process will finish first, receive a fixed percentage of CPU time, or become faster in every situation. Nice values matter most when CPU-bound processes are runnable at the same time.

A process waiting for disk, network, memory, or another external resource may not benefit noticeably from a more favorable nice value. Nice changes CPU scheduling preference; they do not directly add disk, network, memory, or GPU capacity.

Understanding the nice-value scale

On standard Linux systems, nice values normally range from -20 through 19. A newly started process normally has a nice value of 0, unless it inherits a different value from its launching process.

  • Lower numeric values mean a stronger CPU scheduling preference.
  • Higher numeric values mean a weaker CPU scheduling preference.
  • Moving from 0 to 10 makes a process less competitive for CPU time.
  • Moving from 0 to -10 makes a process more competitive for CPU time.
Nice value or rangeRelative CPU scheduling preferenceTypical permission requirementAppropriate use
-20Highest ordinary nice-based preferenceRoot or authorized sudoRare, carefully controlled CPU-bound work
-19 to -1Higher than normalRoot or authorized sudoImportant workloads when the administrator accepts the impact
0Normal defaultNormal process startupGeneral interactive and service workloads
1 to 19Lower than normalUsually available to the process ownerNon-urgent background work
19Lowest ordinary nice-based preferenceUsually available to the process ownerBatch work that should yield readily

Permissions and ownership

An unprivileged user can generally change the nice value only for processes that user owns. A regular user can usually make an owned process nicer by raising its value, for example from 0 to 10.

Lowering a nice value increases CPU preference. Assigning a negative value, or reducing an existing value, normally requires elevated privileges through sudo or the root account. Linux resource limits, security policy, containers, cgroups, and service configuration can impose additional restrictions.

Use sudo only when you are authorized to change the workload. A highly favorable priority can make other applications or services less responsive.

Starting a command with nice

nice starts a new command with an adjusted nice value. With no explicit adjustment, the usual GNU/Linux behavior is to add 10 to the inherited nice value:

nice command

The common option form is:

nice -n 10 command

Here, -n 10 is an explicit adjustment. In the usual case where the launching shell has nice value 0, the command starts at value 10. Technically, this option adds to the inherited value rather than always assigning an absolute target. This distinction matters when the shell itself already has a nonzero nice value.

For learners, nice -n N command is the clearest syntax. A positive adjustment lowers CPU scheduling preference:

nice -n 15 vim
nice -n 10 tar -czf backup.tar.gz important-data/

The second example is suitable for non-urgent, CPU-intensive backup work. To request a negative adjustment, use elevated privileges:

sudo nice -n -15 important-job

The command must appear after the nice options. If the command requires its own privileges, those are separate from the privilege needed to set its nice value.

Changing an existing process with renice

renice changes the nice value of a process that is already running. A PID, or process identifier, is the numeric address of a running process and is the most useful target for a first lesson.

For Linux's usual renice implementation, -n specifies the process's new nice value. Raise the value to reduce an owned process's CPU preference:

renice -n 10 -p 14475

Lowering the value requires authorization:

sudo renice -n -5 -p 14475

Several PIDs can be supplied when supported by the implementation:

sudo renice -n 5 -p 14475 14502 14518

Implementations may also provide selector options for process groups or users. Consult the local renice manual before using those modes. PID-based use is easier to verify and is the recommended starting point.

CommandWhen to use itTargetExamplePrivilege considerations
niceWhen launching a new commandThe command about to startnice -n 10 commandPositive adjustments are generally available; negative adjustments usually need sudo or root
reniceWhen changing an existing processOne or more PIDs, and sometimes groups or usersrenice -n 10 -p 14475Owners can generally raise the value; lowering it normally needs sudo or root

Finding the process to adjust

Before changing priority, verify the process's command, owner, PID, and current nice value. For example, find instances of vim with:

ps -o pid,user,ni,comm -C vim

To inspect all processes with their owners, nice values, and commands:

ps -eo pid,user,ni,comm --sort=ni

You can inspect one known PID in more detail:

ps -p 14475 -o pid,user,ni,comm

Interactive tools are also useful. Run top, or use htop if installed, to inspect running processes and their current NI values. Confirm the command and owner carefully before applying a change, especially on a shared server.

TaskCommand patternWhat to look for
Locate a processps -o pid,user,ni,comm -C commandCorrect command, PID, owner, and current NI
Display PID and NIps -eo pid,user,ni,commThe PID and numeric nice value
Launch with adjusted nice valuenice -n 10 commandThe new process inherits the requested adjustment
Change a running processrenice -n 10 -p PIDSuccess message and the intended PID
Verify the changeps -p PID -o pid,ni,commNI matches the intended value

Verifying the result

The NI column is the displayed nice value:

ps -p 14475 -o pid,ni,comm

A successful result might show an NI value of 10 after the process was made less competitive for CPU time. Monitoring tools may also show PRI. NI is the nice value; PRI is a scheduler-related priority field calculated or displayed by the monitoring tool. They are not interchangeable.

Practical expectations and limitations

  • Nice values influence ordinary CPU scheduling, primarily when runnable processes compete for CPU time.
  • They do not directly increase disk throughput, network bandwidth, memory, or GPU capacity.
  • An I/O-bound process waiting for storage or network data will not automatically run faster after its nice value is lowered.
  • cgroups, containers, systemd service settings, resource limits, and other scheduler policies can dominate the observed result.
  • Real-time scheduling uses special scheduler policies separate from ordinary nice tuning and has stricter privilege and safety considerations.

Use a higher nice value for non-urgent CPU-intensive work such as compression, compilation, backups, indexing, and media conversion. Use a lower nice value only for a legitimately important CPU-bound workload and only when the system administrator accepts the effect. Monitor CPU usage and system load, and revert an inappropriate adjustment.

Troubleshooting nice and renice

Permission denied or operation not permitted

This usually means you are trying to assign a negative nice value, lower an existing value, or modify a process owned by another user. Confirm ownership and use sudo only when authorized. If sudo still fails, review resource-limit and system-policy settings.

The process does not exist

The PID may be incorrect, or the process may have ended before renice ran. Find it again with ps, top, or htop, then use the current PID.

The command succeeds but the program is not faster

The workload may be I/O-bound, may not be competing for CPU, or may be constrained by a cgroup, container, service policy, or another scheduler setting. Check CPU usage and system load, then identify the actual bottleneck.

Interactive applications become sluggish

A CPU-intensive process may have been given too much scheduling preference. Move it toward a higher nice value with an authorized command, or stop the job if necessary:

sudo renice -n 10 -p 14475

Confusion about larger numbers

Nice is counterintuitive. A larger number means the process is nicer to other processes and yields more readily. Lower number means stronger CPU preference.

Exam-relevant summary

  • nice starts a new command with an adjusted nice value.
  • renice changes the value of an already-running process.
  • The normal range is -20 through 19, with 0 as the usual default.
  • Lower nice numbers mean higher CPU scheduling preference; higher numbers mean lower preference.
  • Regular users can generally raise the nice value of processes they own.
  • Negative values and reductions normally require root or authorized sudo.
  • Use ps, top, or htop to confirm the PID, owner, command, and NI value.

For related process-priority practice, see Change Process Priority.