HMC Homepage      CS Home

Running Long Jobs

nicing programs

Running long jobs tends to slow a machine down very significantly. This can significantly impede other users in attempting to use the machine. Therefore, the polite thing to do is to run long jobs at a lower priority, thus ensuring that other users are not as significantly affected. The commands to do this are nice (1) and renice (8).

Any program which you expect will run for more than one or two minutes should be run with nice. Nice is a command which will execute a program at a lower than normal priority. If you realize after running a program that it is going to run longer than a couple of minutes, renice will lower the priority of a running process.

Unfortunately, there are two versions of nice, one a shell built-in command, and another which resides in /bin. The /bin/nice version is recommended. If you just run nice, you will get the shell built-in command instead. Therefore, you should always specify /bin/nice.


In order to run a command using nice, use a syntax like

% /bin/nice -number command

Command is the program you want to run, including all command line arguments; just insert whatever you would normally type to run the program. Number is a priority level. Higher numbers are lower priorities, with a default of 0 if you just run a program without nice. The lowest possible priority corresponds to a number of 19. If your program will run for more than 10 or 15 minutes, you should probably use 19, which means your program will run only when no other process wants the CPU. For shorter programs, a 4 or 5 should be sufficient. A 0 is the default priority for running programs. So if you have a very long job to run called foobar, your command line would look something like

% /bin/nice -19 foobar

If you ran foobar without realizing that it would be a very long running program, you can use renice to alter its priority. Watch out, though; renice will only lower a program's priority, so if you make the priority too low, you can't raise it again. This simply means your program might take a long time to run. The syntax for renice is

% /usr/ucb/renice number PID

where PID is the process ID; the command ps (1) will tell you this. So for example, our foobar command would be something like:

% foobar & (runs foobar in the background)

% ps

" PID TTY TIME COMD

" 7112 pts/105 0:09 foobar

% /bin/renice 19 7112


Notes:

  • For more information on setting niceness, see the manual pages for nice (1) and renice (1b).

  • Staff reserves the right to kill any job which is taking far too much CPU time. We are much less likely to kill processes if you tell us about them in advance, however, so it would be in your best interest to send a short note to consult@cs.hmc.edu before starting long jobs.

  • If you are writing a program which will need to run for a long time, try to write it so it can be stopped and restarted later. For example, instead of keeping all of your results in memory and then writing them all out at once when your program exits, write results to a file as they are generated, so if your process is killed (or simply dies on its own) you have some results to show for all the time you used.

  • Current Computer Science Department policy on running long jobs is located at http://www.cs.hmc.edu/qref/policy.html

Copyright (c) HMC Computer Science Department. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with the no Invariant Sections, with no Front-Cover Texts, and with no Back-Cover Texts. A copy of the license is included in the section entitled ``GNU Free Documentation License.''

HMC Computer Science Department
Contact Information
Last Modified Friday, 31-Jan-2003 16:51:32 PST