Change Process Priority in Linux
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.
$ 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
That was just one piece. The course teaches the whole path — from your first command to exam day.