How to Change Process Priority using Linux Nice and Renice
In a Linux system, there are hundreds of processes, that are continuously running different tasks. Linux Kernel does a fantastic job of mediating between these processes and allotting CPU to these processes.
Every running process in Linux has a priority assigned to it. We can change the process priority using nice and renice utility.
With the help of the Nice command in Linux, you can set process priority. If you give a process a higher priority, then Kernel will allocate more CPU time to that process.
The Nice command will launch a process with a user-defined scheduling priority. Renice command will modify the scheduling priority of a running process. Linux Kernel schedules the process and allocates CPU time accordingly for each of them.
The process scheduling priority range is from -20 to 19. We call this a nice value.
Nice value of -20 represents the highest priority, and a nice value of 19 represents the least priority for a process.
Follow the below process to increase the priority of any process:
1. Login into your Linux system via user name and password, enter # top command.
After hitting enter you will get output like above screen, in that NI means Nice Value of particular process.
2. We can set NI value of any process or command in 2 ways.
a) In the output of # top command, just enter ” r ”, we get the screen like below:
By default when a program is launched in Linux, it gets launched with the priority of ‘0’. However, you can change the priority of your service yourself.
Simply just put the PID of any process or the PID of that process in which you want to increase the priority. Hit enter after putting PID.
It will ask for Renice value, see the above screen. put the value priority range is from -20 to 19. We call this a nice value. Nice value of -20 represents the highest priority, and a nice value of 19 represents the least priority for a process.
After putting the renice value, the process priority will change according to NI value.
Check the NI column after purring renice value of any process, see below screen.
In the above screen, PID of kthreadd is 2 and its nice value has been changed to -10, which means now it has higher priority among then all process, which is running under a Linux system.
We can also set the NI nice value of any process like httpd, java, mysql , ftp , sshd to make that service perform fast.
b) We can set NI via another way, by using simple below command
After top command, do the below step to increase the performance of any service, or process
# nice -10 httpd
Above command will set NI value of httpd service to 10, means it has lower priority among all the running process under Linux system.
# nice –10 httpd
The above command will set NI value of httpd service to -10, which means it has the highest priority, we can increase this value to -20, A nice value of -20 represents the highest priority.
For more information visit Ideastack.

