Page Body

Modifying Process Priorities With Nice and Renice

Every process on a GNU/Linux system has a nice value, which helps determines its importance regarding access to computing resources, relative to other processes. These values can be modified.

Note: If you are not familiar with the GNU/Linux command line interface, review the Conventions page before proceeding.

nice

The nice command can start a program with a modified scheduling priority:

nice ex_command

When provided a command name (i.e., ex_command), the nice command starts a process with a lower priority level. By default, this priority level is 10.

A specific priority level can be specified via the -n (--adjustment=ex_nice_value) option:

nice -n ex_nice_value ex_command

For example, the following command starts gedit with a nice value of 15:

nice -n 15 'gedit'

renice

If a process is already running, the renice command can be used to alter its priority.

renice ex_nice_value ex_identifier...

Aside from being the name of a process, ex_identifier can also be a process group ID (GID)/group name if the -g (--pgrp) option is used, or a user ID (UID)/username if the -u (--user) option is used. reniceing a process group causes all processes in the process group to have their scheduling priorities altered. reniceing a user causes all processes owned by the user to have their scheduling priority altered.

Users other than the root user may only alter the priority of processes they own. Also, a non-root user can only increase the nice value (i.e., select a lower priority) for a process and this change is irreversible, unless the user has a sufficient nice resource limit (run man 1 ulimit and man 1 getrlimit for more information).

If you want to decrement or increment a priority level for a running process, instead of specifying a specific priority level, you can do so with - and +, respectively:

renice -ex_nice_value ex_identifier...

renice +ex_nice_value ex_identifier...

Command substitution and the pgrep command can be used to find and target similarly named processes, as well:

renice -ex_nice_value $(pgrep ex_target)

renice +ex_nice_value $(pgrep ex_target)

Documentation

For more on the nice and renice commands, refer to their man pages by running man 1 nice and man 1 renice, respectively.

Avatar

Enjoyed this post?

Subscribe to the feed for the latest updates.