Understanding the Process Priorities on RHEL 8 illustrates how the system manages process priorities when a program is executed.
On a Linux system, when you run a program or command without explicitly setting its priority, it starts with a default nice value of 0. Regardless of whether we’re using Red Hat Enterprise Linux, this concept applies to the majority of Linux distributions.
Understanding the Nice Values
The nice value determines the priority of a process in terms of CPU scheduling. Here’s how it works:
- Range of nice values:
-20
(highest priority) to19
(lowest priority) - Default value:
0
(normal priority) - Lower nice value → higher priority
- Higher nice value → lower priority
Based on it, let’s analyze some examples:
1- Considering that we have two processes:
Process A = -18 priority/nice value
Process B = 7 priority/nice value
What is the process with a higher chance of receiving CPU allocation?
The answer is: Process A!
2- Considering that we have three processes:
Process X = 0
Process Y = 0
Process Z = -20
What is the process with a higher chance of receiving CPU allocation?
The answer is: Process Z. Processes X and Y will “fight” for equality in CPU allocation.
To check the process priority (aka nice value), we can:
top

Or execute the “ps” command with the following parameters:
ps -eo "%p %n %C %U %x %c"
Note: The parameter “-o” allows us to specify which field to display. The “%n” shows the nice value of the process:


Commands Overview
Let’s execute the following command and analyze its priority (nice value):
dd if=/dev/zero of=/dev/null &
As we can see in the following picture, the process “dd” was started in the background and its priority (nice) is “0” (default value):

To execute a program/command with a custom priority (nice value):
nice -n 5 <program/command>
In this case, for instance, we’re running the “dd” command with a nice value of 5:

We can also change the priority of a running program with the “renice” command. To do that, we need the process ID (PID) of the program/command. For example:
renice -n -19 48921
- -n -19 –> new priority/nice value
- 48921 –> process ID (PID) that will receive the new priority/nice value

Note: We got “Permission denied” because we cannot increase the priority of a running process (only the root user can do that). Since we’re running this command with a normal user (non-root), we get a permission-denied error. Otherwise, we can decrease the priority/nice value, for example:

That’s it for now 🙂