Background jobs: &, jobs, fg, bg

Updated November 1, 2026

A trailing & runs a command in the background: the shell is free at once. You manage your jobs with jobs, fg, bg.

sleep 100 &      # into the background
jobs             # the job list
fg %1            # bring job 1 to the foreground
Ctrl+Z           # suspend, then bg %1 to resume in the background

Sample output

$ sleep 300
^Z
[1]+  Stopped                 sleep 300
$ jobs
[1]+  Stopped                 sleep 300
$ bg %1
[1]+ sleep 300 &
$ jobs
[1]+  Running                 sleep 300 &
$ kill %1
[1]+  Terminated              sleep 300

Jobs belong to the current shell. If the shell closes, its background jobs usually go with it.

Common mistakes

jobs, fg and bg work only in an interactive shell. Inside a script the same line answers bash: line 1: fg: no job control and returns 1: job control is off there, and numbers like %1 do not exist. In a script you drive a background process by PID: command &, then PID=$! and wait $PID.

A background job that wants keyboard input gets stopped by the kernel. cat > /tmp/x.txt & turns into [1]+ Stopped cat > /tmp/x.txt almost at once. That is not a failure, it is SIGTTIN: only the foreground job may read from the terminal. Bring it back with fg %1, or give it input from a file instead.

The shell will not close while stopped jobs exist: the first exit prints There are stopped jobs. and leaves you where you were. A second exit right after closes the shell together with those jobs, and the work of the suspended program is gone. Check jobs, bring back what you need with fg, and leave after that.

Used in

You need this in the lesson Processes and jobs.