Learn how to change process priority in Linux or Unix. Using renice command understand how to alter priority of running processes.
Processes in kernel have their own scheduling priorities and using which they get served by kernel. If you have loaded system and needs 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. Process with low nice values gets service before process with high nice value. So if you want a particular process to get served first you need to lower its nice value. Administrator may also choose to mark negative nice value (down upto -20) to speed up processes further more. Lets see how to change process priority –
There are 3 ways to select target for
renice command. Once can submit process id (PID) or user ID or process group ID. Normally we use PID and UID in 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 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 particular user then you can submit UID of that user using
-u option. This option is useful when you want all processes by user to complete fast, so you can set 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 above example, there are two processes owned by user4 with priority 0. We changed priority of user4 to 2. So both processes had their priority changed to 2.
Normal user can change his own process priority too. But he can not override priority set by administrator. -20 is lowest minimum nice value one can set on system. This is speediest priority, once set that process gets service and all available resources on system to get its task done.