Skip to main content

Background job handler in linux | Unix

On Unix-like operating systems, bg is a job control command. It resumes suspended jobs in the background, returning the user to the shell prompt while the job runs. The presence of bg is required for a shell to comply with the POSIX standard.

POSIX:

Short for Portable operating system interface for Unix, POSIX is a set of IEEE and ISO standards that define how Unix operating systems operate with one another and the command structure.

This document covers the bash built-in implementation of bg.

Syntax

bg [job]

Options

job         Specifies the job that you want to run in the background.

Job number 1 is referred to as %1, job number 2 is referred to as %2, etc.;

%, %+, or %% refers to the current job;

%- or - refers to the previous job.

Examples

In this example, let's assume we are in the bash shell.

If you initiate a process at the command line, and you want to return to the command line prompt before the program is finished executing to do something else (e.g., check your mail, edit a text file, whatever) you can press Control-Z and the job will stop.

If you then run the command: bg %1 The stopped job will resume operation, but remain in the background. It will not receive any input from the terminal while it's in the background, but it will keep running, and you can continue to use the shell from the command line.

Related commands

cancel — Cancels a print job under the System V operating system.
fg — Resumes a suspended job and brings it to the foreground.
jobs — List the status of all running jobs.
kill — Send a signal to a process, affecting its behavior or killing it.
lpstat — List the status of the LP print services.
ps — Report the status of a process or processes.
stop — Stop a running job.

Comments