CrackOps
Interview PrepTracksLinuxAWS LabSoonInterview RoomSoon
Sign inStart free
CrackOps

Interview prep for the people who keep production up.

[email protected]
ProductInterview PrepTracksDashboardInterview Room
RolesDevOpsSREPlatformCloud
CompanyAboutContactPrivacyTerms
© CrackOps
Linux / Process Management / bg

bg

Resume a stopped job in the background

Beginnerjob controlshell

bg resumes a job you stopped with Ctrl-Z, but in the background, so the prompt stays yours. It's the fix for 'I started a long command and forgot the &': Ctrl-Z, then bg.

Syntaxbg [%JOB...]

Watch it run

You started a big archive in the foreground and need your prompt back without starting over.

devops@devops-lab: ~ — zsh — 96×28
➜ ~
Step 1 of 4
tar czf ~/backups/www-2026-10-29.tar.gz /var/www

tar is running and holding your terminal. Ctrl-Z stops it. Nothing is lost: it is paused mid-archive, with its files still open.

Anatomy of a command

$
commandbg

bash builtin: sends SIGCONT to a stopped job without giving it the terminal.

How it works

bg looks up the job in the shell's job table, marks it as running in the background and sends SIGCONT to its whole process group with killpg. Unlike fg, it does not call tcsetpgrp, so the terminal stays with the shell and keyboard signals (Ctrl-C, Ctrl-Z) no longer reach the job. The job's stdin, stdout and stderr still point at the terminal: output is printed in between your commands (unless stty tostop is set, which stops writers with SIGTTOU), and if the job tries to read from the terminal the kernel sends it SIGTTIN, which stops it again. bg is the same as having started the command with & in the first place, except that you decided after it was already running.

Options you'll actually use

(no argument)Resume the current job (+) in the background
%NResume job number N
%N %MResume several jobs at once
%string / %?stringJob whose command starts with / contains string

Common mistakes

Ctrl-Z, then logging out, assuming the job keeps running

Ctrl-Z stops the job; it does nothing until resumed. On logout it gets SIGHUP (and dies) or stays stopped forever.

Ctrl-Z, bg, then disown -h %1 (or use nohup/tmux from the start)
bg on a command that prompts for input

A background job that reads the terminal is stopped by SIGTTIN, so it never gets anywhere.

Answer the prompt with fg, or run it non-interactively (--yes, < /dev/null)
Putting a chatty command in the background with bg

Its output still goes to the terminal and gets mixed with whatever you type next.

Start it with output redirected: cmd > out.log 2>&1 &

Interview questions

Practice

Try these on a Linux machine of your own. Each task has a hint and a solution.

  1. 1

    Run `sleep 300` in the foreground, stop it, and resume it in the background. Check that it's running.

  2. 2

    Stop two foreground sleeps one after the other, then resume both with one bg command.

  3. 3

    Background a stopped job, then detach it from the shell so it survives logout.

Related commands

fgBring a job back to the foregroundjobsList the shell's background and stopped jobsnohupKeep a command running after you log outkillSend a signal to a process
PreviousjobsNextfg
Linux / Process Management / bg

bg

Resume a stopped job in the background

Beginnerjob controlshell

bg resumes a job you stopped with Ctrl-Z, but in the background, so the prompt stays yours. It's the fix for 'I started a long command and forgot the &': Ctrl-Z, then bg.

Syntaxbg [%JOB...]

Watch it run

You started a big archive in the foreground and need your prompt back without starting over.

devops@devops-lab: ~ — zsh — 96×28
➜ ~
Step 1 of 4
tar czf ~/backups/www-2026-10-29.tar.gz /var/www

tar is running and holding your terminal. Ctrl-Z stops it. Nothing is lost: it is paused mid-archive, with its files still open.

Anatomy of a command

$
commandbg

bash builtin: sends SIGCONT to a stopped job without giving it the terminal.

How it works

bg looks up the job in the shell's job table, marks it as running in the background and sends SIGCONT to its whole process group with killpg. Unlike fg, it does not call tcsetpgrp, so the terminal stays with the shell and keyboard signals (Ctrl-C, Ctrl-Z) no longer reach the job. The job's stdin, stdout and stderr still point at the terminal: output is printed in between your commands (unless stty tostop is set, which stops writers with SIGTTOU), and if the job tries to read from the terminal the kernel sends it SIGTTIN, which stops it again. bg is the same as having started the command with & in the first place, except that you decided after it was already running.

Options you'll actually use

(no argument)Resume the current job (+) in the background
%NResume job number N
%N %MResume several jobs at once
%string / %?stringJob whose command starts with / contains string

Common mistakes

Ctrl-Z, then logging out, assuming the job keeps running

Ctrl-Z stops the job; it does nothing until resumed. On logout it gets SIGHUP (and dies) or stays stopped forever.

Ctrl-Z, bg, then disown -h %1 (or use nohup/tmux from the start)
bg on a command that prompts for input

A background job that reads the terminal is stopped by SIGTTIN, so it never gets anywhere.

Answer the prompt with fg, or run it non-interactively (--yes, < /dev/null)
Putting a chatty command in the background with bg

Its output still goes to the terminal and gets mixed with whatever you type next.

Start it with output redirected: cmd > out.log 2>&1 &

Interview questions

Practice

Try these on a Linux machine of your own. Each task has a hint and a solution.

  1. 1

    Run `sleep 300` in the foreground, stop it, and resume it in the background. Check that it's running.

  2. 2

    Stop two foreground sleeps one after the other, then resume both with one bg command.

  3. 3

    Background a stopped job, then detach it from the shell so it survives logout.

Related commands

fgBring a job back to the foregroundjobsList the shell's background and stopped jobsnohupKeep a command running after you log outkillSend a signal to a process
PreviousjobsNextfg