It becomes obvious when using the nice command that it is unable to alter the scheduling priority of processes that are already running. This means nice allows setting priority when the process is stopped.
In this situation, the renice command excels. We shall examine the renice command in Linux and its examples throughout the following few sections.
Linux renice command
The renice command modifies one or more running processes' nice values. The nice value is the process's system scheduling priority in decimal form. The impacted processes' process IDs are by default used to identify them. When a process group is specified, the request is made for all the processes in that group.
The nice value of the processes is determined differently depending on the implementation. If the requested raise exceeds the implementation-dependent limits and raises or lowers the nice value of the performed utility, the limit whose value was exceeded is used.
Any process' priority can be changed, and it can be set to any number between -20 and 20 if you have root user authority. If you don't have root user authority, you can only reset and raise the priority of processes that you own in the range of 0 to 20, with 0 being the lowest priority.
Syntax
renice [-n] <priority> [-p|--pid] <pid>...
renice [-n] <priority> -g|--pgrp <pgid>...
renice [-n] <priority> -u|--user <user>...
Change priority of process using renice
Let us see the different examples of the usage of renice command one by one. Finding the PID (process ID) of the process you wish to change is a prerequisite for using renice. The ps command can be used to accomplish this.
ps -l
The 8th column shows the current nice value.
Increase priority of a process
The -n option can be used to change the process priority. To increase the priority value we will have to pass a negative value.
Example:
renice -n -19 -p 24016
To change the priority value we have simply passed the new nice value and passed the process group id with the help of the -p parameter.
To verify that the nice value has changed you can run the following command:
ps -l
You can clearly see this in the 8th column the nice values have been changed successfully of already running processes.
Lower the priority of a process
In the same, if we have to lower the priority value we can achieve that with the -n parameter but now by passing positive values instead of negative value.
Example:
renice -n 5 -p 24016
Verify the nice values with the help of the following command:
ps -l
For a specific group
You can change the priority of every process in a group by using the -g option. The next command will set all of the processes that belong to linuxuser group nice value to 10.
renice -n 10 -g linuxuser
For a specific user
Renice enables you to change the priority of every process owned by a particular user. For this use the -u option.
renice -n 7 -u linuxuser
All of the processes controlled by the user linuxuser will have their priority changed by the abovementioned command. All of the processes that belong to the user linuxuser will be given the new nice value of 7.
Options
Useful renice Linux command options:
Options | Description |
---|---|
-n | Set the process, process group, or user's scheduling priority specifically. It is optional to specify the option -n or --priority, but if it is, it must be the first input. |
-g | Consider the succeeding arguments to be process group IDs. |
-p | The succeeding arguments should be interpreted as process IDs (the default). |
-u | Consider succeeding arguments to be usernames or UIDs. |
-V | Show the version information and then exit. |
-h | Show the help text, then exit. |
Conclusion
The renice command is useful if you need to specify a specific process' priority so that the kernel may load and run it while properly managing CPU resources. Commonly used to give the process the highest priority. nice and renice commands often go together because functionally both do the same.
Renice can be used to fine-tune process priorities. By carefully adjusting the priorities of different processes, you can optimize your system's performance in ways that wouldn't be possible with other methods.
To know more about the renice command run the below command in your terminal :
man renice
Navigate all-in-one place of Linux Commands for more learning.
Comments