Friday, January 29, 2010

Linux Process Prioritization

It can become annoying while waiting on your Linux system to complete a long process. Whatever the process might be you can help speed things along and give more cpu shares to your task. The top command lets you see the current processes running on your Linux machine. One of the columns you will see is the PR which stands for priority.

The lower the PR number the more cpu shares your process will get. The way to manipulate process priorities is with the nice and renice commands. For example, I have VirtualBox running an installation on my system. The top command is reporting alot of free cpu % because VirtualBox is getting it's resources capped due to the current priority.

sudo renice -20 pid

The pid will need to be the id of the process you are wanting to manipulate. In this case we are running renice and setting a priority of -20 (the lower the better) on our process id. Once complete our PR value changes from 20 to 0 and our NI value changes to -20. This dedicates more cpu power to our task and will hopefully cut down on the time it takes for our process to complete.

The same thing can be done to lower the importance of a process.

sudo renice 20 pid

The command above will raise the priority of the process matching our pid. The effect of raising the PR value will cause the process to get less system resources. This can be handy if your running a large task and want to use the system for other things at the same time.

Please note that nice and renice are common Linux/Unix tools however the syntax of the command is not always the same. The example above was from an Ubuntu system. On other distrobutions you might have to add flags such as -n or -p to make this command work. When in doubt check your manpages

man renice

No comments:

Post a Comment