Change process priority

nice command

Sometimes you might want to change the priority of a process in Linux. For example, you might run a process that is very important and you want it to finish quickly. You can change the process priority using the nice command and give that process more CPU time.

Every process running on your system has a nice value. By default, the nice value is set to 0. The process priority range is from -20 to 19.

Here are a few facts about changing the priority of a process:

  • the lower number is better (the process with the lower number will get more CPU time).
  • a regular user can set nice values only from 0 to 19 and only on the its own processes.
  • a regular user can set the nice value only higher, not lower.

For example, to launch vim with a priority of 15, we would type the following command:

linux nice command 1

To launch vim with a negative priority of -15, we would use the following command:

linux nice command 2

Notice that we had to supply the root password. That is because we wanted to specify a negative priority, which can be done only by root.

renice command

The renice program can be used to change the priority of a process that is already running. Only root can lower the priority of a process. You need to specify the PID of the process whose priority you would like to modify. For example, to modify the priority of the process with the PID of 14475 we would use the following command:

linux renice command

Geek University 2022