DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 

bg(1)


bg -- run jobs in the background

Synopsis

/usr/bin/bg [job_id ...]

Description

This shell script executes the builtin command of the same name as implemented by the /u95/bin/sh shell. See ksh(1) for more information on this shell.

If job control is enabled (see the description of set -m on the ksh(1) manual page), the bg utility resumes suspended jobs from the current shell environment by running them as background jobs.

If the job specified by job_id is already a running background job, the bg utility has no effect and will exit successfully. Using bg to place a job into the background causes its process ID to become ``known in the current shell execution environment'', as if it had been started as an asynchronous list. See ksh(1) for more information on asynchronous command execution and job control.

Operands

The job_id parameter specifies the process ID of the job to be resumed as a background job. If no job_id operand is given, the most recently suspended job is used. Background jobs for the current shell can be displayed using the jobs(1) or ps(1) commands.

Environment variables

The following environment variables affect the execution of bg:

LANG
Provide a default value for the internationalization variables that are unset or null. If LANG is unset or null, the corresponding value from the implementation-specific default locale will be used. If any of the internationalization variables contains an invalid setting, the utility will behave as if none of the variables had been defined.

LC_ALL
If set to a non-empty string value, override the values of all the other internationalization variables.

LC_CTYPE
Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments).

LC_MESSAGES
Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error.

Output

The output of bg consists of a line in the format:
   job-id	command
where the fields are as follows:

job-id
A number that can be used to identify the job to the wait(1), fg(1), and kill(1) utilities.

command
The associated command that was given to the shell.

Exit codes

An exit code of 0 indicates successful completion; an exit code greater than 0 indicates an error.

Diagnostics

If job control is disabled, the bg utility will exit with an error and no job will be placed in the background.

Usage

A job is generally suspended by typing the SUSP character (<Ctrl>-Z on most systems); this can be set and displayed through the stty(1) command. At that point, bg can put the job into the background. This is most effective when the job is expecting no terminal input and its output has been redirected to non-terminal files. A background job can be forced to stop when it has terminal output by issuing the command:

stty tostop

A background job can be stopped with the command:

kill -s stop job ID

Warnings

The bg utility will not work as expected when it is operating in its own utility execution environment because that environment will have no suspended jobs. In the following examples:
   . . . | xargs bg (bg)
each bg operates in a different environment and will not share its parent shell's understanding of jobs.

References

fg(1), jobs(1), kill(1), ps(1), ksh(1), wait(1)
© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 25 April 2004