When we work with the nice command, it’s clear that it can’t change the scheduling priority of running processes. As we’ve just seen, we would need to stop and then start the process in this case. This is where the renice command shines. We can leverage the renice command to change the niceness while the process is running. To see the syntax, we would pass the –help option:
# renice --help Usage: renice [-n]
[-p|--pid] ... renice [-n] -g|--pgrp ... renice [-n] -u|--user ... Alter the priority of running processes. Options: -n, --priority specify the nice increment value -p, --pid interpret argument as process ID (default) -g, --pgrp interpret argument as process group ID -u, --user | interpret argument as username or user ID -h, --help display this help and exit -V, --version output version information and exit
renice command may be applied to a process, process group, or user (target). A privileged user may alter the priority of other users’ processes. priority must, for ordinary users, lie between 0 and the environment variable PRIO_MAX (normally 20), with a higher number indicating increased niceness. A higher niceness value means that the process will run at a lower priority. A privileged user may set a negative priority, as low as PRIO_MIN (normally −20), to speed up processes. See the nice command for setting the scheduling priority for processes when they are initially run.
renice Command Examples
1. To set the priority for process:
# renice -n 20 -p 2112 # renice --priority 20 -p 2112
2. To change the priority for process os a group:
# renice -n 20 -g SUPPORT
3. To change the priority for process os a user:
# renice -n 20 u mike
4. To get the version:
# renice -v # renice --version
5. To get the help:
# renice -h # renice --help
The renice command is used to change the nice level of an existing process. Its syntax is as follows:
$ renice -n [NICELEVEL] [PID’s]
Apart from the renice command, the top command can also be used to modify the nice value of a running process. The following steps are used to modify a process priority using the top command:
- Invoke the top command.
- Press r key on the keyboard to bring up the option for specifying a new nice value on the top command’s current interactive session.
- Enter the new nice value and PID, followed by pressing the Enter key.