Linux bg Command: Resume a Shell Job in the Background

bg resumes a stopped job in the background in Bash. It is used when you want to stop a running command with Ctrl+Z and continue using the terminal.

bg sends a continue signal to a stopped job but does not give front control of the terminal. You can check the job number with jobs and specify it like %1. Interactive programs waiting for input may stop again in the background.

Basic syntax

bg [%job number]

The installed implementation and options may vary depending on the distribution. Check the description for your system with help bg.

Examples

Checking stopped jobs

After pressing Ctrl+Z during a foreground command execution, check the status.

jobs -s

Resuming a specific job in the background

In the example, replace %1 with the actual number from the jobs output.

bg %1

Check resume result

Check if it is in the Running state.

jobs -l

Running a Paused Job in the Background

bg continues a job that is currently paused in the background of the current shell. For example, after running sleep 60 and stopping it with Ctrl+Z, check the job number.

jobs
bg %1
jobs

Example of state changes:

[1]+  Stopped  sleep 60
[1]+  Running  sleep 60 &

%1 refers to job number 1 in the current shell, not the PID. If the shell does not support job control or there are no paused jobs, bg will fail. When a job finishes, it may disappear from jobs, so check the status again.

Main Options and Format

Options/Format Description
%N Specify job number N of the current shell.
%+ Specify the current job.
%- Specify the previous job.
Omit argument Use the job that Bash considers the current job.

Precautions when using

A job stopped with Ctrl+Z is not yet running. A job that tries to read from standard input may be stopped again even if resumed with bg. bg is a shell job control feature and cannot be applied to processes started in another terminal.

Frequently Asked Questions

Are appending & at the end of a command and using bg the same?

& starts the command in the background from the beginning, while bg resumes a currently stopped job in the shell in the background.

Official Documentation

The exact behavior of these options and implementation differences can be found in the official bg documentation.