Categories: How-To

Modify the Execution Priority of Processes in Linux [Basic Guide]

It is possible to modify the execution priority of processes on Linux using the nice and renice commands. These commands are extremely useful in multi-user environments

Imagine a server with many users logged in and each one running something. In this type of environment, it is necessary to give more or less processing slices to the various user programs to maintain a stable and organized environment.

Nice command

Use:

$ nice [-n prioritization_setting] [command]

The nice command adjusts a process’s available CPU time to
higher or lower priority.

In English the word “nice” means “cool”. If the adjustment of
The priority for a process is a positive number, meaning that it is
being cooler with the other programs decreasing their priority.

If the adjustment is a negative number, it means that the program is
being less cool, increasing your execution priority and leaving less
CPU time for the other programs.

The possible priority adjustment ranges from —20 (highest priority/least cool) to 19 (coolest, least priority).

If no adjustment value is passed, the nice command will adjust
the priority to +10, reducing the process execution time.

$ nice updatedb &

In this example, the updatedb command has lower execution priority.

$ nice —n —10 payroll

In this example the command
Payroll will be executed with higher priority.

Renice Command

Use:

$ renice [+/-]
setting_priority [options] PID/user

The renice command adjusts the execution priority of processes that are already running. By default, the renice command takes the PID of a particular process as a parameter.

The priority setting is an integer ranging from —20 (highest priority) to +20 (execute anything before this process).

The most common options are:

  • -p: Get a PID to change its priority.
  • -u: Receives a username to change the priority of all processes running on this user.
  • -g: Receives a name from a group to change the priority of all processes belonging to this group.

Example:

# renice -1 987 -u daemon root -p 32

In this example, the process number PID 987, PID 32, and all processes that daemon and root users own will have higher priority.

See how to work with processes in Linux and put processes in the background.

Learn much more about Linux in our online course. You can register here. If you already have an account, or want to create one, just log in or create your user here.

Did you like it?

Share

Uirá Endy Ribeiro

Uirá Endy Ribeiro is a Software Developer and Cloud Computing Architect with a 23-year career. He has master's degrees in computer science and fifteen IT certifications and is the author of 11 books recognized in the IT world market. He is also Director at Universidade Salgado de Oliveira and Director of the Linux Professional Institute - LPI Director's Board.

Uirá Endy Ribeiro

Uirá Endy Ribeiro is a Software Developer and Cloud Computing Architect with a 23-year career. He has master's degrees in computer science and fifteen IT certifications and is the author of 11 books recognized in the IT world market. He is also Director at Universidade Salgado de Oliveira and Director of the Linux Professional Institute - LPI Director's Board.

Recent Posts

Sudo command on Linux (privilege scale) [Basic Guide]

The sudo command on Linux executes a given command as if it were another user.…

2 years ago

SS command on Linux (investigate the network) [Basic Guide]

The ss command on Linux is extremely useful for investigating sockets, providing various information about…

2 years ago

Free Linux command (memory usage) [Basic Guide]

Free Linux command shows the amount of total memory in use and available, as well…

2 years ago

Linux while command (loop – while) [Basic Guide]

The shell has structures for testing conditions and executing certain program sequences several times (loop),…

2 years ago

Linux fstab file (disk mount setup) [Basic Guide]

The /etc/fstab file stores the configuration of which devices should be mounted and what is…

2 years ago

Netcat command on Linux (Swiss network knife) [Basic Guide]

The Netcat Command in Linux or nc is a utility used to do “almost anything”…

2 years ago

This website uses cookies.