Hack 101. Renice Command Examples

by Ramesh

Renice alters the scheduling priority of a running process.

How to decrease the priority of a running process? (Increase nice)

In the example below, an existing shell-script is running at nice value of 10. (6th column in the ps output)

  1. $ ps axl | grep nice-test
  2. 0 509 13245 13216 30 10 5244 968 wait SN pts/1 0:00 /bin/bash ./nice-test.sh

To increase the nice value (thus reducing the priority), execute the renice command as shown below.

  1. $ renice 16 -p 13245
  2. 13245: old priority 10, new priority 16
  3.  
  4. $ ps axl | grep nice-test
  5. 0 509 13245 13216 36 16 5244 968 wait SN pts/1 0:00 /bin/bash ./nice-test.sh

[Note: Now, the 6th column of the nice-test.sh (PID 13245) shows the new nice value of 16.]

How to increase the priority of a running process? (Decrease nice)

In the example below, an existing shell-script is running at a nice value of 10. (6th column in the ps output)

  1. $ ps axl | grep nice-test
  2. 0 509 13254 13216 30 10 4412 968 wait SN pts/1 0:00 /bin/bash ./nice-test.sh

In increase the priority, give a lower nice value as shown below. However, only root can increase the priority of a running process, else you’ll get the following error message.

  1. $ renice 5 -p 13254
  2. renice: 13254: setpriority: Permission denied
  3. Login as root to increase the priority of a running process
  4.  
  5. $ su -
  6.  
  7. # renice 5 -p 13254
  8. 13254: old priority 10, new priority 5
  9.  
  10. # ps axl | grep nice-test
  11. 0 509 13254 13216 25 5 4412 968 wait SN pts/1 0:00 /bin/bash ./nice-test.sh

[Note: The 6th column now shows a lower nice value of 5 (increased priority)]