How To Change The Execution Priority Of A Process In Linux?
 

How To Change The Execution Priority Of A Process In Linux?

 

This post was last updated on August 1st, 2020 at 12:24 pm

In Linux, a process is an instance of a program that is running on a computer. When a program starts executing it can have multiple processes associated with it. These processes can either run by a user or by the operating system itself.  Usually, a process terminates on its own when they are done with their task.

You can change the process priority by using nice and renice commands. The process scheduling priority is ranged from -20 to 19. We can call this nice value. A process with the highest priority will have -20 nice value while a process with the least priority will have 19 nice value.

By default when a process starts it gets 0 nice value.

Display the nice value of a process

You can use the following command in your terminal to display the current priority of a process.

top

This will display output as given below. The NI column in this output shows the niceness or nice value of processes.

 

How to change the priority of an existing process?

Now if you see in the image above mysqld has process id 893 and NI value 0. To change the priority or nice value of an existing process, we will use the following command –

renice  -5 -p 893

After executing this command nice value of mysqld will be changed from 0 to -5.

How to set the priority of a new process?

You can set the priority of a new process by adding the nice command with the command that you are going to run. The syntax of the command can be given as –

nice -n [nice value] [command]

For example –

nice -n 10 sudo apt upgrade

This will start upgrading with a priority of 10 which is less prior then the default value 0. This is useful when you want to upgrade the system but don’t want an extra process burden at a given time.

How the change the priority of processes belongs to a particular group?

To change the priority of all the processes belongs to a particular group use -g option with the renice command. Use the following command –

renice -n 5 -g hr

This will change the current nice value of all processes belongs to group hr to 5.

How to change the priority of all processes owned by a user?

Use option -u to alter the priority of processes owned by a user. You can use the following command to change the priority of processes owned by user lalit.

renice -n -5 -u lalit

The current nice value of all the processes will be changed to -5 which is more prior then the default nice value 0.

Conclusion

By reading this article you are now able to change the priority of a process. If you have any thoughts on this topic then share it with us in the comments below.

Previous 5 Habits I Keep Reminding Myself to Be a Better Developer
Next How To Display Date And Time In The Output Of History Command In Linux?
 

About author

You might also like

Linux Topics 0 Comments

How to check if a disk uses GPT or MBR in Linux?

In a computer, MBR and GPT are two ways of storing the partitioning information on a disk. The MBR is a legacy while GPT is a newer disk partitioning style

How To 0 Comments

How To Disable Secure Boot In A System?

This post was last updated on August 1st, 2020 at 12:47 pmSecure boot is a feature of UEFI which ensures that your PC boots only through the firmware that is

Linux Topics 0 Comments

How To Install GParted On CentOS 8?

Gparted (also known as GNOME partition editor) is a free partitioning tool. This is a GUI application that uses GNU parted in the backend. Gparted is used to create, delete,

0 Comments

No Comments Yet!

You can be first to comment this post!

Leave a Reply