Thursday, October 11, 2012

Nice & Renice: manage the priority of processes

With nice and renice you can control the priority each new process given.

Each process is given an nice number which represents his priority among other processes in the system.
The default nice number given to process is 0

The range of nice numbers is -20 to 19.
-20 is the "highest" priority number. If you want to give your process the highest priority, give it the nice number minus 20
19 is the lowest. it might take time for your process to start running (if at all).

now lets see some examples:

1. Set Nice Number

nice  -n 19  ./scriptos
In this example I started my script "scriptos" with the nice number 19.
I can check the actual priority of the process in two ways:

ps  axl  |  grep  scriptos
The priority will be under PRI column.

2. Change Nice Number

You can change the priority of your process by changing the nice number with renice.
Lets look on the following example:

renice  -n  12  474
12 - the new nice number of the scriptos (instead of 19).
474 - the PID of scriptos.


Post a Comment