[Information Coding Laboratory]

Unix Commands: nohup and nice

For running jobs overnight and without interruption, it is nice to know how these commands work.
nohup This command is designed to let a process continue running after you have logged out. nohup means no-hangup. Normally when you log out, any non-backgrounded processes are sent the HUP or TERM signal so they will stop running (see note from Greg). with nohup that process is adopted by process #1 ( the root process ) and will continue to run while you are out having lunch, dinner, sleeping or whatever. A good way to run something in this manner is to set a job running with nohup and run the output of the process (both stdout and stderr) to a file. Then your data can be analyzed later.

The simplest case is as follows.

Lets say you have a program called longjob which you requires a few cmdline args and which outputs some information. Using the following command:

    % nohup longjob arg1 arg2 >& output.information &
will start the job in the background, save all the output text ( stdout and stderr ) in the output.information file, and will not stop running when you log out.
nice Now that you know how to start jobs in the background, you need to know how to make those jobs be considerate of other users on the machine. The command nice is used to change the priority of a particular job. For most cases, nice will not significantly affect the speed of the job. If no one is working on the machine, there are very few processes running. So even though the 'niced' process is at a lower priority, it still gets the enough processing time to run at nearly its normal speed. If someone sits down on the machine and starts to work, the 'niced' process will get less processor time but the user will not be upset that the machine is running so slow. So it is nice to nice your long jobs.
This works well in conjunction with nohup as well. Simply run the above command as follows:

    % nohup nice -20 longjob arg1 arg2 >& output.information &
This will decrement the job priority by 20 and run it in the background without hanging up on logout.

You'll have to consult the man pages on nice for the exact commandline syntax. I seem to recall a difference between the SGI and SUN calling params. Also, it depends if you are using the csh built-in command, or the binary standalone program.

NOTE from G.Sherwood:

One note about the nohup command. I don't think tcsh (also csh on Solaris) will send the HUP signal by default to any background processes when it exits. You have to use the 'hup' builtin command to get it to do this. I'm just pointing this out because I never use the nohup command when running long jobs - I just put them in the background.
Welcome · Projects · People · Papers · Calendar · Links · Internal
© 1997 Information Coding Laboratory
Send comments to www@code.ucsd.edu

Last Updated: $Date: 1997/11/21 23:04:52 $