nice and renice in Ubuntu

In this article, we would cover nice and renice command-line utilities in Ubuntu. We have already covered how we can renice a process with top command. If you have already read that then, you can directly move to the main section below. We will cover the basics first.

What is a process? A process is an instance of a program. Every process has a nice value. How much CPU access a process can have is decided by the Linux kernel. Amongst numerous parameters, nice value of a process is one crucial factor. The nice value of a process can range between -20 and 19.

When the nice value is set to 19, it shows the process will have lesser access to the CPU. Whereas, when its set at -20 then the higher CPU access for a process. So, lower the nice value of a process the more CPU access it will have and vice versa.

Furthermore, we need to keep certain rules in consideration before we set a nice value of a process. These are –

First, a normal user can only set nice value for a process which the user owns. Whereas, a root user can set nice values for all the processes. Secondly, a normal user can’t lower down the nice value of a process. That means, if a normal user has set nice value of a process to 5. Then, the user isn’t permitted to lower down the nice value to even 4. But, the normal user can set higher values. So, in this case, the user can set any nice value between 6 and 19. Thirdly, the default nice value for a process is set to 0. So, a normal user can’t set a negative nice value.

nice in Ubuntu

When we open an application, it sets the default nice value for the associated process. Alternatively, we can also set nice value ourselves before starting an application –

nice -n N <process_name/command>

where, N ranges between 1 and 19 (nice value).

For instance, to open a Document viewer through terminal –

nice -n 10 evince

For a root user, use sudo (nice value range between -20 and 19).

sudo nice -n N <process_name/command>

Do check the NI column in top command to see the changes in nice value.

renice in Ubuntu

A normal user can’t lower down the assigned nice value. But, a root user can do that. So, use top command to identify the Process ID (PID) of a process. And, then issue the following to renice for a normal user –

renice -n N <PID>

where, N ranges between 1 and 19 (nice value).

For a root user, use sudo (nice value range between -20 and 19) –

sudo renice -n N <PID>

Check the NI column in top command to see the changes made.

In conclusion, we have covered nice and renice in Ubuntu here.

Similar Posts