How to change the priority of a Linux process – What is Nice-value ?
What actually “Nice-value” means ? Why should we bother ?
Every process which are running and waiting to execute has it’s own priority to run/execute. The priority changing is comes under the management of server processor(CPU) time with respect to the processes. Simply the processor or CPU is like a human juggling multiple process at a time. By considering the example of a human who is handling multiple process at a time, really it is very difficult to do with out a proper planning or guidelines. But it is very simple if we have a proper plan or priority for process which has to be done.
In the case of Linux, Nice value of a process determines the priority of that process to CPU. Nice value is a guidelines to the CPU to follow when it is looking at all of the works it has to do.
The Nice value is an integer value which is ranging from -20 to 19 and the default is “0″. Lesser the integer has high Nice value or priority. Which means -20 has higher priority to server processor or CPU.
The Nice value is an integer value which is ranging from -20 to 19 and the default is “0″. Lesser the integer has high Nice value or priority. Which means -20 has higher priority to server processor or CPU.
Nice range : -20 to 19
Default value : 0
How to find out the nice value of a process which is running under the server ?
We can use mainly two commands to find out the Nice-value of a process they are “PS” and “TOP“.
Top displays the dynamic output and the PS shows a static result.
Examples:
Using the command TOP.
Top displays the dynamic output and the PS shows a static result.
Examples:
Using the command TOP.
# top
See the output, there is one value in the result “NI” which is representing the Nice value of the process running under the server.

Using the command PS.
For simplicity we can use PS with custom output.
For simplicity we can use PS with custom output.
# ps -o comm,nice -p PID
The above command will displays the Nice value of the process with that particular PID.
Example:
Example:
[root@server] # ps -o comm,nice -p 30594
COMMAND NI
cpanellogd - sl 18
“nice” and “renice” commands to set and reset the Nice value of a process.
Setting priority on new processes with “nice” command.
Setting priority on new processes with “nice” command.
Which means, we can start a process with our own costum Nice value on it
. Lets see how can it possible.
Use the command nice to set its Nice vale:
Syntax:
Use the command nice to set its Nice vale:
Syntax:
# nice $NI Command
Here NI represents the Nice value which we want to set.
Example:
Example:
# nice -20 ping localhost
I’ve selected the PING command to demonstrate the nice. Execute the above command under screen.
Nice value details from PS
# ps aux |grep ping
root 24728 0.0 0.0 8136 744 pts/3 SN+ 08:39 0:00 ping localhost
-bash-3.2# ps -o comm,nice -p 24728
COMMAND NI
ping -20
That’s it !
Resetting the priority for already existing Process.
You can change the Nice value of a process which is already executing under your server by using the “renice” command.
Syntax:
You can change the Nice value of a process which is already executing under your server by using the “renice” command.
Syntax:
# renice $NI -p PID
Here NI represents the new Nice value.
Example:
Example:
# renice 0 -p 24728
24930: old priority 19, new priority 0
# ps -o comm,nice -p 24728
COMMAND NI
ping 0
That’s it 
See also,
Iftop for BW monitoring
Iftop for BW monitoring
No comments:
Post a Comment