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
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.
nice -n -5 bash
First observe output of top without setting nice value of any process in below image
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
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.
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
2371 (process ID) old priority 0, new priority 5
You can also see this priority using top command(see highlighted line in image).
- Exit status of a child process in Linux
- Process states and Transitions in a UNIX Process
- Linux Virtualization : Linux Containers (lxc)
- Communication between two process using signals in C
- Maximum number of threads that can be created within a process in C
- Maximum number of Zombie process a system can handle
- while command in Linux with example
- who command in Linux
- Filters in Linux
- The Linux Kernel
- Linux Commands
- Linux vs Unix
- Permissions in Linux
- 'dd' command in Linux
- 10 Best Linux VPS Hosting
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.