z/OS UNIX System Services User's Guide
Previous topic | Next topic | Contents | Contact z/OS | Library | PDF


Starting a job in the background with an ampersand (&)

z/OS UNIX System Services User's Guide
SA23-2279-00

To start a command as a background job, end the command line with an ampersand (&). For example:
sort myfile >myout &
When the background job starts to run, the system:
  1. Assigns it a job identifier, a process group ID (PGID), and a process ID (PID).
  2. Displays the job identifier (in brackets) and one or more PIDs (more than one if there is a pipe).
  3. Issues the shell prompt so that you can enter another command.
The first (or only) PID is also the PGID. This is an example of the output when you enter a background command:
$sort myfile >myout &
[3] 717046
$
3 is the job identifier and 717046 is the PID and PGID.

Tip: Note the PID numbers and the job number when you create a background job; you can use them to check the status of the job or to end it.

Unlike a batch job, a shell job running in the background directs its output to standard output, your workstation screen. If you do not want to have this output interfering with your work in the foreground, remember to redirect the output to a file when you start a background command. After the output is redirected, you can look at it whenever it is convenient.

A background job can be suspended. A background job that attempts to read from stdin is suspended until it is made the foreground process. Therefore, if a program reads from stdin, you may want to redirect stdin from a file. Also, if the tostop setting of the terminal is enabled (you can set or query this by using the stty command), output from a background job causes the job to be suspended.

Go to the previous page Go to the next page




Copyright IBM Corporation 1990, 2014