Up to main menu         Back to Korn Shell, C Shell         Next: Types of Files

Background Processes

To run a command in the background, append the ampersand character, ``&'', to the command, e.g.,
	pascal>  a.out > results.txt &
Running the process in the background means that it will chug away while you can type and execute other commands in the same window. Otherwise, you wouldn't be able to type another command until the first one was completed. However, if the program requires input from the keyboard, or produced output to the window, then you will encounter problems trying to run the process in the background.

When you run jobs in the background, you can get a listing of those jobs by tying the command jobs. To select one of those jobs to return to the foreground, use fg, e.g., fg 3.

In fact, you can start a program running in the background, log off, go away, and have the program continue to run while you eat lunch and take a nap. To insure that the process continues to run even after you exit, precede the command with ``nohup'' (no hang-up). Also, as a courtesy to any user who actually sits at that console and logs on to the computer, precede the command with ``nice'', which runs your command considerately -- not hogging the CPU from the person actually logged on to the same computer. (This is ``enforced courtesy'' -- if you run a huge background program which is not nice'd, the systems administrator may kill that job. It's the law.)

Here is the full (Korn shell) command which will run a program in the background, nicely, without quitting when you log off, taking its input from file input.txt and sending output to output.txt and sending standard error to stderr.txt;

   pascal>  nohup  nice  a.out < input.txt > output.txt 2> stderr.txt &

Up to main menu         Back to Korn Shell, C Shell         Next: Types of Files

Bruce.Fast@Colorado.EDU