[ Bottom of Page | Previous Page | Next Page | Contents | Index | Library Home | Legal | Search ]

Commands Reference, Volume 2

fg Command

Purpose

Runs jobs in the foreground.

Syntax

fg [JobID]

Description

If job control is enabled (see "Job Control in the Korn Shell" in AIX 5L Version 5.2 System User's Guide: Operating System and Devices), the fg command moves a background job in the current environment into the foreground. Use the JobID parameter to indicate a specific job to be run in the foreground. If this parameter is not supplied, the fg command uses the job most recently suspended, placed in the background, or run as a background job.

The JobID parameter can be a process ID number, or you can use one of the following symbol combinations:

%Number Refers to a job by the job number.
%String Refers to a job whose name begins with the specified string.
%?String Refers to a job whose name contains the specified string.
%+ OR %% Refers to the current job.
%- Refers to the previous job.

Using the fg command to place a job into the foreground removes the job's process ID from the list of those known by the current shell environment.

The /usr/bin/fg command does not work when operating in its own command execution environment, because that environment does not have applicable jobs to manipulate. For this reason, the fg command is implemented as a Korn shell or POSIX shell regular built-in command.

Exit Status

The following exit values are returned:

0 Successful completion.
>0 An error occurred.

If job control is disabled, the fg command exits with an error, and no job is placed in the foreground.

Examples

If the output of the job -l command shows the following job running in the background:

[1] + 16477RunningSleep 100 &

use the process ID to run the sleep 100 & command in the foreground by entering:

fg 16477

The screen displays:

sleep

Files

/usr/bin/ksh Contains the Korn shell fg built-in command.
/usr/bin/fg Contains the fg command.

Related Information

The bg command, csh command, jobs command, kill command, wait command.

Job Control in the Korn Shell in AIX 5L Version 5.2 System User's Guide: Operating System and Devices.

[ Top of Page | Previous Page | Next Page | Contents | Index | Library Home | Legal | Search ]