Learn how to change process priority in Linux or Unix. Using the renice command understands how to alter the priority of running processes.
Processes in the kernel have their own scheduling priorities and using which they get served by the kernel. If you have a loaded system and need to have some processes serve before others you need to change process priority. This process is also called renicing since we use
renice command to change process priority.
There are nice values defined from 0 to 20. 20 being the highest. The process with low nice values gets service before the process with a high nice value. So if you want a particular process to get served first you need to lower its nice value. Administrators may also choose to mark negative nice value (down up to -20) to speed up processes furthermore. Let’s see how to change process priority –
There are 3 ways to select a target for
renice command. Once can submit process id (PID) or user ID or process group ID. Normally we use PID and UID in the real-world so we will see these options. New priority or nice value can be defined with option
-n. Current nice value can be viewed in top command under NI column Or it can be checked using below command :
# ps -eo pid,user,nice,command | grep 30411 30411 root 0 top 31567 root 0 grep 30411
In above example, nice value is set to 0 for give PID.
Renice process id :
Process id can be submitted to
-p option. In below example we will renice value to 2 for pid 30411.
# renice -n 2 -p 30411 30411: old priority 0, new priority 2 # ps -eo pid,user,nice,command | grep 30411 747 root 0 grep 30411 30411 root 2 top
renice command itself shows old and new nice values in output. We also verified new nice value using
Renice user id :
If you want to change priorities of all processes of a particular user then you can submit UID of that user using
-u option. This option is useful when you want all processes by the user to complete fast, so you can set the user to -20 to get things speedy!
# ps -eo pid,user,nice,command | grep top 3859 user4 0 top 3892 user4 0 top 4588 root 0 grep top # renice -n 2 -u user4 54323: old priority 0, new priority 2 # ps -eo pid,user,nice,command | grep top 3859 user4 2 top 3892 user4 2 top 4966 root 0 grep top
In the above example, there are two processes owned by user4 with priority 0. We changed the priority of user4 to 2. So both processes had their priority changed to 2.
Normal users can change their own process priority too. But he can not override priority set by the administrator. -20 is the lowest minimum nice value one can set on the system. This is the speediest priority, once set that process gets service and all available resources on the system to get its task done.