bg(C)


bg, fg -- run jobs in the background or foreground

Syntax

bg [ job_ID ... ]

fg [ job_ID ... ]

Description

bg and fg are job control commands built into the Korn shell (see the set -m command on the ksh(C) manual page).

bg resumes suspended jobs and runs them in the background. job_ID specifies the jobs to run in the background (use jobs(C) to find the ID of a job). If job_ID is not specified, bg picks the most recently suspended job.

See jobs(C) for a description of the acceptable formats of job_ID.

bg reports the job_ID and command associated with the job on the standard output in the format:

   [ job_ID ] command
fg moves jobs running in the background to run in the foreground. If job_ID is not specified, fg picks the job that was most recently suspended, placed in the background, or run as a background job (using &).

fg reports the command associated with the job on the standard output in the format:

command

Suspending jobs

Suspend a job using the SUSP character (defined using stty(C) with the susp option). A process that is suspended while expecting input from a terminal will remain inactive when put in the background; jobs to be suspended should have their standard input, output and error redirected away from the terminal.

Examples

Bring the current default job to the foreground:

fg %%

Put the suspended current default job in the background to run:

bg %+

Bring the next current default job to the foreground:

fg %-

Stop the background job whose command begins with the string ``foo'':

kill -s stop %"foo"

Stop the background job that has ID 3:

kill -s stop %3

Resume execution of the job with ID 3 in the background:

bg %3

Define the SUSP character as <Ctrl>z:

stty susp ^Z

Prevent background processes owned by the current shell from writing to the terminal (this also stops them if they try to output to the terminal):

stty tostop

Allow background processes owned by the current shell to write to the terminal:

stty -tostop

Limitations

The commands bg and fg are only available as built-in commands in ksh(C).

You must have enabled job control (using set -m) to use bg and fg.

See also

jobs(C), kill(C), ksh(C), stty(C), wait(C)

Standards conformance

bg and fg are conformant with:

ISO/IEC DIS 9945-2:1992, Information technology - Portable Operating System Interface (POSIX) - Part 2: Shell and Utilities (IEEE Std 1003.2-1992);
X/Open CAE Specification, Commands and Utilities, Issue 4, 1992.


© 2005 The SCO Group, Inc. All rights reserved.
SCO OpenServer Release 6.0.0 -- 03 June 2005