fbpx Linux Process Priority: nice and renice | Certificação Linux

Mastering Process Priority in Linux: nice, renice, Terminal Tuning

📅 04/01/2019 ⏱ 3 min ✍️ Uira Ribeiro
Linuxhow-to
Mastering Process Priority in Linux: nice, renice, Terminal Tuning
Exam Pass App — mais de 7.000 questões LPI, offline, em 5 idiomas, disponível no Android e na App Store
Available on
Google Play
Available on
App Store

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

Imagine a server with many logged-in users 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 keep a stable and organized environment.

The nice command

Usage:

$ nice [-n priority_adjustment] [command]

The nice command adjusts the available CPU time of a process to a higher or lower priority.

In English, the word "nice" means "kind". If the priority adjustment for a process is a positive number, it means it is being kinder to other programs by decreasing its priority.

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

The possible priority adjustment ranges from –20 (higher priority / less kind) to 19 (more kind, lower priority).

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

$ nice updatedb &

In this example the updatedb command has lower execution priority.

$ nice –n –10 folha_pagamento

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

The renice command

Usage:

$ renice [+/-] priority_adjustment [options] PID/User

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

The priority adjustment is an integer number ranging from –20 (highest priority) to +20 (run anything before this process).

The most common options are:

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

Example:

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

In this example, the process with PID 987, PID 32, and all processes owned by users daemon and root will have higher priority.

&list=PL6IznNGWCdD89jP8kiacplFQcJlmMmjhb&index=64

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 enroll here. If you already have an account, or want to create one, just log in or create your user here.

Liked it? Share

Uira Ribeiro

Prof. Uirá Ribeiro

Chair do Board do Linux Professional Institute

After years of watching professionals waste hours on simple tasks because they didn't know the right Linux tools, I decided to teach.
Today I'm the author of most of LPI's official Learning Materials and mentor to over 14,000 certified students.

See my full story →

That was just one piece. The course teaches the whole path — from your first command to exam day.

Certificação Linux — a plataforma líder em certificações Linux no Brasil
WhatsApp