Open In App

Priority of process in Linux | nice value

Last Updated : 01 Apr, 2018
Improve
Improve
Like Article
Like
Save
Share
Report

The running instance of program is process, and each process needs space in RAM and CPU time to be executed, each process has its priority in which it is executed.

Now observe the below image and see column NI

top

Output:

top command output

The column NI represents nice value of a process. It’s value ranges from -20 to 20(on most unix like operating systems).

  -20                         20
most priority           least priority    
  process                  process

One important thing to note is nice value only controls CPU time assigned to process and not utilisation of memory and I/O devices.

nice and renice command
nice command is used to start a process with specified nice value, which renice command is used to alter priority of running process.

Usage of nice command :
Now let’s assume the case that system has only 1GB of RAM and it’s working really slow, i.e. programs running on it(processes) are not responding quickly, in that case if you want to kill some of the processes, you need to start a terminal, if you start your bash shell normally, it will also produce lag but you can avoid this by starting the bash shell with high priority.

For example:

nice -n -5 bash

First observe output of top without setting nice value of any process in below image

nice value of top is 0

Now start a bash shell with nice value -5, if you see the highlighted line, the top command which is running on bash shell has nice value set to -5

nice value of bash shell is -5

Usage of renice command :
To alter priority of running process, we use renice command.

renice value PID

value is new priority to be assigned
PID is PID of process whose priority is to be changed

One thing to note is you can’t set high priority to any process without having root permissions though any normal user can set high priority to low priority of a process.

We will see one example of how you alter priority of process.

nice value of gnome terminal is 0

You can observe that nice value of process(PID = 2371) is 0, now let’s try to set the new priority of 5 to this process.

renice 5 2371

Output:

2371 (process ID) old priority 0, new priority 5

You can also see this priority using top command(see highlighted line in image).

process 2371 has nice value 5


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads