The Single UNIX ® Specification, Version 2
Copyright © 1997 The Open Group


bg - run jobs in the background


bg [job_id ...]


If job control is enabled (see the description of set -m), the bg utility resumes suspended jobs from the current environment (see Shell Execution 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 Lists .




The following operand is supported:
Specify the job to be resumed as a background job. If no job_id operand is given, the most recently suspended job is used. The format of job_id is described in the entry for job control job ID in the XBD specification, Glossary  .


Not used.




The following environment variables affect the execution of bg:
Provide a default value for the internationalisation variables that are unset or null. If LANG is unset or null, the corresponding value from the implementation-dependent default locale will be used. If any of the internationalisation variables contains an invalid setting, the utility will behave as if none of the variables had been defined.
If set to a non-empty string value, override the values of all the other internationalisation variables.
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).
Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error.
Determine the location of message catalogues for the processing of LC_MESSAGES .




The output of bg consists of a line in the format:

"[%d] %s\n", <job-number>, <command> where the fields are as follows:

A number that can be used to identify the job to the wait, fg and kill utilities. Using these utilities, the job can be identified by prefixing the job number with "%".
The associated command that was given to the shell.


Used only for diagnostic messages.






The following exit values are returned:
Successful completion.
An error occurred.


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


A job is generally suspended by typing the SUSP character (<control>-Z on most systems); see the XBD specification, General Terminal Interface  . 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

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

each bg operates in a different environment and will not share its parent shell's understanding of jobs. For this reason, bg is generally implemented as a shell regular built-in.






fg, kill, jobs, wait.

UNIX ® is a registered Trademark of The Open Group.
Copyright © 1997 The Open Group
[ Main Index | XSH | XCU | XBD | XCURSES | XNS ]