This website uses cookies. By using this site, you consent to the use of cookies. For more information, please take a look at our Privacy Policy.
Home > Wiki encyclopedia > FG

FG

The fg instruction is one of the commonly used instructions under Linux. The fg instruction is used to switch the background or suspended tasks (or jobs) to the foreground.

Catalogues

Introduction

'FG' explanation: foreground

Description: If job control is enabled (refer to "Job Control in Korn Shell" in AIX 5L V5.2 System User Guide: Operating System and Devices), the fg command moves background jobs in the current environment to the foreground. Use the JobID parameter to indicate the specific job to run in the foreground. If this parameter is not provided, the fg command uses the job that was recently suspended in the background or runs as a background job.

Purpose: The fg instruction is used to switch the background or suspended tasks (or jobs) to the foreground. If there are multiple commands in the background, you can use the fg + background job bow command to transfer to the foreground to continue running. [1] 

Syntax: fg [JobID]

The JobID parameter can be the identification number of the process, or you can use the following symbol combination:

%Number refers to the job by job number.

%String refers to a job whose name starts with a specific string.

%?String refers to a job whose name contains a specific string.

%+ OR %% refers to the current job.

%- Reference to the previous job.

Using the fg command to bring a job to the foreground will cause the identifier of the job process to be removed from the list, which is known to those in the current shell environment. [2] 

The /usr/bin/fg command does not work when operating in its own command execution environment because there is no suitable job available in this environment. For this reason, the fg command is executed as a regular built-in command in the Korn or POSIX shell.

Exit status

The following export values are returned:

0 Successfully ended.

>0 An error occurred.

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

Examples

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

[1] + 16477 RunningSleep 100 &

You can use the process identifier to run the sleep 100 & command in the foreground, just enter:

fg 16477

The screen will display:

sleep

file

/usr/bin/ksh contains Korn shell fg built-in commands.

/usr/bin/fg contains the fg command.

Scope of application: Red Hat, RHEL, Ubuntu, CentOS, SUSE, openSUSE, Fedora

Related instructions:

bg: Put the job (or task) in the background.

Jobs: Display shell job information.

Related literatures

ASSOCIATED PRODUCTS

FPGA Tutorial Lattice FPGA
Need Help?

Support

If you have any questions about the product and related issues, Please contact us.