How to change the priority of a Process?

In this article, we cover how to change the priority of a running process. Whether you run a process in the background or foreground, it will consume precious system resources. And, when multiple processes are running at once, things can get pretty tough to handle in no time.

That doesn’t mean running the processes sequentially would do some good. There will always be a tradeoff. Running multiple processes parallelly can consume higher system resources. On the other hand, running the processes sequentially takes time.

So, if we could change the priority of the running processes then that brings efficiency to our work.

How to change the priority of a Process

We use nice and renice command-line tools to change the priority of a process. The range of nice values for a process is between -20 and 19. To understand how it functions, the lower the nice value the higher is processes’ priority and vice versa.

The default nice value of a process is 0 (Zero). In addition, the regular user isn’t allowed to lower the nice values. Furthermore, it can only change the priority of its own processes.

For processes that haven’t yet been started, use a nice command-line utility. To change the priority of already-running processes use renice command.

To change the priority of a process:

sudo nice -n N <process_name/command>

or,

sudo renice -n N <Process_ID>

Use htop tool to verify Nice values and lookup Process ID. Nice values would be available in the NI column.

We can change the priority of the process even without Administrative rights. But, remember there are limitations. As we have already covered above, a regular user isn’t allowed to use lower values than those already assigned. And, it can only change that for its own processes.

In conclusion, we have covered how to change the priority of a process.

Additional Info:

We have already covered how to install htop in AlmaLinux 9. When it comes to Ubuntu, open a terminal and issue the following command:

sudo apt update
sudo apt install htop

To run htop:

htop

Press F3 to Search. Enter the search term, for instance: gnome-calculator, and press Enter. It highlights the Process Name and shows us the relevant data.

Similar Posts