Processes and tasks

Command bg

Continue task in background

Linux · Bash examples · commands run on the selected server

When to use bg

Use bg to resume a stopped job in the background of the same interactive shell. Shell job control is distinct from service management and does not make a task survive every disconnect.

Syntax

bg [%JOB]

Square brackets mark optional arguments; an ellipsis means repetition. Replace example file names, user names and server addresses with your own values.

Common options and arguments

No arguments
Continue the currently stopped job in the background.
%N
Select task by number from jobs.

Usage examples

Run test task

sleep 120 &

A temporary sleep process starts in the background and the shell returns a job reference.

View shell jobs

jobs -l

The current shell's jobs and process IDs are displayed.

Continue a stopped job

bg %1

Job one is resumed in the background if it is stopped; its number must match the current job list.

Notes and limitations

  • bg is a built-in interactive shell command with job control enabled.
  • The job must first be stopped, for example Ctrl+Z; number %1 check with jobs.

Common questions and troubleshooting

Why does bg say no such job?

Job numbers belong to the shell that created them. Reconnecting starts another shell and does not restore the old job table.

Why does a background job stop again?

An interactive command may try to read from the terminal. Bring it to the foreground or use a tool designed for unattended execution.

Further help

Options vary by version and distribution. Check the installed documentation with this command: help bg.