Blog

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.

A 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, and enter the # top command.

Cheap Linux VPS 1

After hitting enter you will get output like the above screen, in that NI means Nice Value of a particular process.

2.

We can set the NI value of any process or command in 2 ways.

a)

In the output of the # top command, just enter ” r ”, and we get the screen like the one 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.

Cheap Linux VPS 2.a1

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.

Cheap Linux VPS 2.a2

It will ask for Renice value, see the above screen. put the value priority range from -20 to 19. We call this a nice value. A 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 the NI value.

Check the NI column after purring renice value of any process, see below screen.

Cheap Linux VPS 2.a3

In the above screen, the PID of kthreadd is 2 and its nice value has been changed to -10, which means now it has higher priority among then all processes, which is running under a Linux system.

We can also set the NI nice value of any process like httpd, java, MySQL, FTP, or sshd to make that service perform fast.

b)

We can set NI via another way, by using the simple below command.

After the top command, do the below step to increase the performance of any service, or process.

# nice -10 httpd

The above command will set the NI value of the httpd service to 10, which means it has lower priority among all the running processes under the Linux system.

# nice –10 httpd

The above command will set the NI value of the 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.

Conclusion

Still, confused about how to change process priority using Linux nice and renice? Contact Ideastack now.

Frequently Asked Questions

Q1. What is nice in Linux?

Nice is a program that may be found on Unix and Unix-like operating systems like Linux. It corresponds straight to the same-named kernel call. Nice is used to call a utility or shell script with a specific CPU priority, allowing the process to receive more or less CPU time than other processes.

Q2. What is nice value?

The process’s priority is determined by the value. The process is considered to be “nicer” than other processes the higher the value, the lower the priority. On Linux workstations, the nice value by default is set to 0. The size of the process in memory is shown in the SZ field.

Q3. What is nice and renice in Linux?

The nice command sets the priority of a Linux process before it runs. It is not possible to change the priority after it has been established using the nice command. In this case, you can use the renice command. With the renice command, the priority of an active process can be modified.

×

Hello!

Click one of our contacts below to chat on WhatsApp

×