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

Change Process Priority in Linux

📅 10/02/2018 ⏱ 2 min ✍️ Uira Ribeiro
Linux
Change Process Priority in Linux
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

Do you know the nice and renice commands?

It is possible to change the execution priority of processes using the nice and renice commands. These commands are extremely useful in multi-user environments, where it is necessary to give more or less processing time slices to the various user programs, to keep a stable and organized environment.

&feature=youtu.be

$ nice [-n ajuste_de_prioridade] [comando]

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 nicer to other programs by lowering its priority.

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

The possible priority adjustment ranges from -20 (highest priority / least nice) to 19 (nicest, lowest 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 adjusts the execution priority of processes that are already running. By default, the renice command takes the PID of a specific process as a parameter. The priority adjustment is an integer that ranges from -20 (highest priority) to +20 (run anything before this process).

The most common options are:

  • -p: Takes a PID to change its priority.
  • -u: Takes a username to change the priority of all processes belonging to that user that are running.
  • -g: Takes 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, process number PID 987, PID 32, and all processes owned by users daemon and root will have higher priority.

[divider style='full']

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.

Like 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