Whereas nice is used to start a new process, the renice command enables you to alter the scheduling priority of an already running process. You use the -n option to specify the new nice value that you want the process to have. When you renice a process group with the -g option, it causes all processes in the process group to have their nice value altered. When you renice a user with the -u option, it alters the nice value of all processes owned by the user. By default, the processes affected are specified by their PIDs.
Syntax
The syntax of the renice command is:
# renice [-n {nice value}] [options] {identifier}
If you encounter the below error while running the renice command:
renice: command not found
you may try installing the below package as per your choice of distribution:
OS Distribution | Command |
---|---|
OS X | brew install util-linux |
Debian | apt-get install bsdutils |
Ubuntu | apt-get install bsdutils |
Alpine | apk add util-linux |
Arch Linux | pacman -S util-linux |
Kali Linux | apt-get install bsdutils |
CentOS | yum install util-linux |
Fedora | dnf install util-linux |
Raspbian | apt-get install bsdutils |
Ordinary users can increase the nice level of their own processes, while the superuser can also decrease it (increasing the priority) and can operate on any process. The valid range is −20 to +20, but avoid high negative numbers or you might interfere with vital system processes.
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
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
6. Change priority of all processes owned by a user:
# renice -n niceness_value -u user
7. Change priority of all processes that belong to a process group:
# renice -n niceness_value --pgrp process_group
Conclusion
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.