In a vast majority of cases, Linux does a fantastic job of automatically scheduling processes. The more urgent processes are given a higher priority, and the less urgent processes a lower priority. In rare circumstances, the scheduler might not prioritize processes as you would like. For example, backup processes could be taking up resources that you would rather be used serving web pages. If you would like to regain a bit control over process priorities, the nice and renice commands will give you some.
The nice command controls the priority of a process right when you start it. Here’s an example:
nice -n 19 ./script.sh &
Running the nice command by itself just prints the current niceness of the shell, usually 0. (The niceness numbers range from a high of -20 to a low of 19. Niceness is like golf; the lower the number, the better off the process is.) The -n flag is needed to specify the niceness level. In the above example, script.sh is run in the background with the lowest possible niceness.
The nice command only sets the niceness right when a process is started. If you find yourself wanting to change the niceness of a process that is already running, the renice command handles that scenario.
renice 12 -p 73682
renice first takes the niceness level you want to set, then uses the -p flag to specify the number of the process you want to change. The ps command can help you track down the ID number of the process you want to renice.
While setting a process’s niceness can help manage your server’s resources, it is not a panacea. The gains you might get from setting the proper niceness just might not be enough to handle the load on your server. Should this prove to be the case, do not hesitate to contact our Heroic Support® team. We will happily take a look at your server and make recommendations.
Liquid Web’s Heroic Support is always available to assist customers with this or any other issue. If you need our assistance please contact us:
Toll Free 1.800.580.4985
Our Sales and Support teams are available 24 hours by phone or e-mail to assist.