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).
- Nice and Renice Command in Linux with Examples
- Process states and Transitions in a UNIX Process
- Exit status of a child process in Linux
- Process Management in Linux
- Getting System and Process Information Using C Programming and Shell in Linux
- Linux Virtualization : Linux Containers (lxc)
- Difference Between Arch Linux and Kali Linux
- Maximum number of Zombie process a system can handle
- Maximum number of threads that can be created within a process in C
- Communication between two process using signals in C
- How to find time taken by a command/program on Linux Shell?
- Terminal Mail and Linux Security Mail
- Linux Virtualization - Chroot Jail
- Linux Kernel Module Programming: Hello World Program
- Formatted text in Linux Terminal using Python
- Some useful Linux Hacks
- Daily life Linux Commands
- Basic Linux Commands for day to day life
- Initializing and Cache Mechanism in Linux Kernel
- How to add "graphics.h" C/C++ library to gcc compiler in Linux
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.