How to change job/process priority in Linux?

Suppose you ran a command and it is taking a lot of time. So what we can do, we can increase its priority so that it will take a slightly less time as usual. The priority of any command/job/process in Linux can be increased by using renice command. 
	To understand priority value in linux, you should know what values of priority is assigned default to any process in linux. The default priority value assigned is 0 in linux. So if we compare below two commands, then we will observe that these two commands are same. 
	[root@saket ~]# nice -n 0 gedit 
	[root@saket ~]# gedit 
	Both will run a program named gedit with priority 0. 
	Now the second point is that what is meant by increasing priority in linux.  Increasing priority in linux means forcing a task to execute faster, by optimizing its schedule of operation. “Schedule of operation” means linux will modify the way this task is scheduled to increase the number of ms of CPU devoted to this task. 
	Another interesting thing to note in linux is that negative nice value increases the speed of the task, implies negative value means increasing priority in linux. I have seen many of my colleagues making this value +19, and thereby decreasing its priority and assume that they have increased the priority. So always remember we need to make this value negative to increase its priority. The priority range lies between +20(lowest) to -20(highest), these twenty ranges occurs from 0 to 19. Now suppose I want to increase priority of a task then i will fire below command. 
	[root@saket ~]# gedit & 
	[1] 26942 
	[root@saket ~]# ps -ef | grep 26942 
	root     26942 32242 15 19:09 pts/3    00:00:01 gedit 
	root     26944 32242  0 19:09 pts/3    00:00:00 grep 26942 
	[root@saket ~]# renice -19 26942 
	26942: old priority 0, new priority -19 
	Now this will increase the priority of the program gedit. 
	I hope you have understood how to change priority in linux. I generally use this when copying data from one server to another or between different disks, or any task which is urgent and we need to complete it in less time. However it only increases the schedule how the task is executed and can’t increase the speed to data transmission, etc. But nevertheless the best what we can do as a linux/unix admin to gear up our tasks. 
0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments