Managing Priority of Linux Process

Introduction:

By default, Linux kernel considers all processes equally important and allocates the same amount of CPU time for each process. Sometimes, you might want to increase or decrease the priority of certain processes to utilize more CPU time.

Process Definition:

A process is a running program. So, any running program or a command given to a Linux system is called a process. Linux can run a lot of processes at a time, which can slow down the speed of some high priority processes result in poor performance. The default value of all the processes is 0.

Nice and Renice Command:

Sometimes, we might want to increase or decrease the priority of certain processes to utilize more CPU time. This is where the nice and renice commands comes in help. Nice command is used for run a process with a user defined priority whereas renice command changing the priority of an already running process. With the help of nice command in Linux you can set process priority. If you give a process a higher priority, then kernel will allocate more CPU time to that process. Nice command will launch a process with a user defined scheduling priority.

Whenever a process start normally, it gets the default nice value (0). If you start a process with nice command without any arguments, it gets the default value of 10. Here 10 is the niceness value of priority. Niceness values range from -20 to 19. The negative values such as -20 gives higher priority to a process and positive values such as 19 gives lower priority.

Regular users are not allowed to start a process with higher priority. You need to be root user to launch any process with higher priority.

Display process nice values
[root@asim ~]#ps –l
Display customize process
[root@asim ~]#ps axo user, pid, nice, command
Display customize process sorted by nice
[root@asim ~]#ps axo user, pid, command, nice – – sort=nice
Start process with nice default value is 10
[root@asim ~]#nice vim text &
Start the process with 15 nice value
[root@asim ~]#nice – 15 vim text &
Change nice value of running process to 19
[root@asim ~]#renice 19 9182 Or [root@asim ~]#renice 19 –p 9182
Run Top press r to renice a process
[root@asim ~]#top
Another way to change nice value
[root@asim ~]#nice – – 15 vim &
Change priority for all running process of user
[root@asim ~]#renice –n -20 –u champ

Leave a Reply

Your email address will not be published. Required fields are marked *