Be Nice To Your Server: Setting Process Priorities

Posted on by Patrick Hawkins | Updated:
Reading Time: 2 minutes

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.

Setting Priorities

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.

Changing Priorities

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.

Renice Sparingly

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
International 517.322.0434
support@liquidweb.com
https://manage.liquidweb.com/

Avatar for Patrick Hawkins

About the Author: Patrick Hawkins

Patrick Hawkins is a former Test Engineer and Managed WordPress admin with Liquid Web

Latest Articles

Blocking IP or whitelisting IP addresses with UFW

Read Article

CentOS Linux 7 end of life migrations

Read Article

Use ChatGPT to diagnose and resolve server issues

Read Article

What is SDDC VMware?

Read Article

Best authentication practices for email senders

Read Article