Getting Started with Unix: 10 Background and Foreground Jobs

The C-shell environment (one of the more commonly provided shells) provides facilities for manipulating jobs and sessions. The default shell on the OUCS Unix system is the TC shell which is very similar to the C shell but with enhanced features. Normally, when a command is given it is executed immediately and it is not possible to give other commands until it has been completed. This mode of working is referred to as running jobs in the foreground. It is also possible to run a job in the background, that is, to cause the command to be executed as a separate process, leaving the terminal free for other work. To start a background job, place an ampersand character at the end of the command line before pressing <Return>.

Example

% maple < run1 > run1out &

This will cause the Maple program, using the data file run1, to be run as a background job, placing the results into the file run1out.

A job that is currently running in the foreground may be suspended and then sent to the background. To suspend, or stop, a foreground job, press <Ctrl/Z>; this temporarily stops the job from running and returns to the normal system prompt. The suspended job may then be re-started in the background by typing bg, or brought to the foreground by typing fg.

Example

% maple < run2

<Ctrl/Z>

% bg

%

These commands run a Maple program, taking its input from the file run2. This job is then suspended, then started again but this time in the background for completion.

There are commands for listing all the jobs, foreground, stopped and background, that are currently running, and for killing jobs. See the man entries for csh and kill for further details.