Pcornel
Browse topics
Options
Recent
Favorites
Linux · Technical reference

bg / fg

Direct answer

Job control in an interactive shell: Ctrl+Z suspends the foreground job, bg resumes it in the background, fg brings it back, jobs lists them, and & starts a command in the background.

When to use this

Use it to manage several tasks in one terminal, or to keep a long task running after logout.

First 30 seconds

1. jobs -l — job list and state.

2. Stopped → bg %n or fg %n.

3. Must survive logout → disown -h %n, or start it in tmux.

4. Long jobs → systemd-run --user --unit=<name> <cmd>.

5. Check it still runs after logout: pgrep -a <name>.

Operational verification

command started (fg or &) → Ctrl+Z stops it → bg/fg resume it → terminal hangup kills it unless detached

Evidence · next step

For Processes → bg / fg, continue with the first unproven Topic check: Confirm the exact interactive shell and its current job table. If that boundary is healthy, advance to the adjacent check: Map shell job ID to the actual process group/PIDs before signaling or troubleshooting. Preserve the same host/time/identity scope and rerun the original workload before accepting recovery.

Continue only after interpreting the current observation.
Context & applicabilityCommon mistakes · platform/version boundaries
Platform / version applicability
linux
applies
Structured applicability is explicit Topic metadata; it does not infer compatibility beyond the stored rows.
At a glance

Operational reference

Fast context before you go deeper.

Platformlinux
Scope / prerequisiteUse it to manage several tasks in one terminal, or to keep a long task running after logout.
What next?3 suggested next steps
Evidence1
On this pageJump to a specific section
Operational workflow

Verification & Troubleshooting

Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.

5 steps Observe → verify → isolate → change minimally → repeat the original test.
ObservedRecord what the original test actually shows

Capture the concrete output, symptom, packet, log or counter before changing anything.

Step 1 Operational evidence path Verify boundary

interactive shell → job/process group → stopped/running state → bg or fg transition → terminal foreground process group → signal/TTY behavior → workload result

Healthy evidence: the intended shell job enters the expected foreground/background state, retains appropriate terminal behavior and the actual workload behaves as intended.

Step 2 Verification and output interpretation Verify boundary

Existing fast checks for this Topic. - Confirm the exact interactive shell and its current job table.

  • Map shell job ID to the actual process group/PIDs before signaling or troubleshooting.
  • Check controlling TTY/session and whether logout/HUP behavior matters.
  • Use a service manager or deliberate detachment mechanism when persistence is required, then verify the workload independently.

Verification chain. interactive shell → job/process group → stopped/running state → bg or fg transition → terminal foreground process group → signal/TTY behavior → workload result

Step 3 Commands Verify boundary
sleep 300 &
jobs
fg %1
bg %1
nohup cmd &
Step 4 Failure modes and next checks Narrow the fault

Suspicious evidence: a backgrounded job is mistaken for a durable service or a shell job ID is confused with a PID.

bg/fg shows a shell job-control transition, not daemonization, persistence after logout or service health.

Step 5 Common mistakes Narrow the fault
  • Background jobs killed on logout (use nohup, tmux or systemd).
Evidence references

Evidence · 1 on this Topic

Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.

observation · 1
Key points

Background jobs still die when the terminal closes (SIGHUP) — use nohup, disown, tmux/screen, or a systemd-run unit for long work. A background job that reads from the terminal stops (state T).

Key checks
  • jobs -l — jobs with PIDs and state
  • fg %1 — bring job 1 to the foreground
  • bg %1 — resume job 1 in the background
  • nohup <cmd> & — survive logout
ReferenceWhat it is1 section · depth on demand

Core model

Identify the controlling shell, terminal and job ID before interpreting job-control state. Foreground status affects terminal access and signal delivery from the TTY; backgrounding does not detach a process from the session or make it survive logout. Distinguish shell jobs from daemon/service lifecycle management.

ReferenceImportant terms & boundaries5 sections · depth on demand

What this shows and what it does not

bg/fg shows a shell job-control transition, not daemonization, persistence after logout or service health.

In depth

Job control: foreground, background, bg and fg

Bash's job control lets you run several programs from one terminal: pause them, move them to the background and bring them back. The bash(1) manual page describes the tools:

  • Ctrl-Z suspends the foreground process, with SIGTSTP.
  • jobs lists the shell's jobs.
  • bg resumes a job in the background, and fg brings it to the foreground.
  • %n refers to job number n, %string to a job whose command starts with the string, and %?string to one that contains it.

On exit, a shell sends SIGHUP to its jobs. disown -h protects a job from that, and the huponexit option makes login shells send SIGHUP to all jobs when they exit.

Commands

ActionCommand
Start in the backgroundlong-task &
Suspend the foreground jobCtrl-Z
Continue in the backgroundbg or bg %2
Bring to the foregroundfg or fg %1
List jobs with PIDsjobs -l
Wait for background jobswait or wait %1
Keep running after logoutdisown -h %1, nohup cmd &
Kill a jobkill %1

Surviving logout: which tool

ToolWhen
nohup cmd > out.log 2>&1 &Quick one-off; ignores SIGHUP
disownA job that's already running
tmux / screenInteractive work you want to reattach to later
systemd-run --user --unit=job cmdLogged, controllable, survives the session (with lingering)
A proper service unitAnything permanent
host$ tar czf /srv/backup/home.tar.gz /home 2>/dev/null
^Z
[1]+  Stopped                 tar czf /srv/backup/home.tar.gz /home 2> /dev/null
host$ bg
[1]+ tar czf /srv/backup/home.tar.gz /home 2> /dev/null &
host$ sleep 600 &
[2] 10234
host$ jobs -l
[1]- 10220 Running                 tar czf /srv/backup/home.tar.gz /home 2> /dev/null &
[2]+ 10234 Running                 sleep 600 &
host$ fg %1
host$ disown -h %2
host$ systemd-run --user --unit=reindex --same-dir ./reindex.sh
host$ journalctl --user -u reindex -f

Background jobs and the terminal

A background job that tries to read from the terminal is stopped with SIGTTIN. One that writes still prints to the terminal, mixed with your prompt, unless its output is redirected. For anything that takes more than a few minutes, tmux or systemd-run are more robust than &. A dropped SSH connection doesn't affect them.

Documented example, not captured output.

Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.

How it works at runtime

bg / fg is part of Processes → bg / fg. bg and fg are shell job-control operations that continue a stopped job in the background or bring a shell-managed job to the foreground; they operate on the shell job table, not on arbitrary system services.

Topic-specific state model. bg and fg are shell job-control operations that continue a stopped job in the background or bring a shell-managed job to the foreground; they operate on the shell job table, not on arbitrary system services.

Interpretation rule. - Background job ≠ detached daemon or persistent service.

  • Shell job ID ≠ system PID.
  • bg success ≠ job will survive terminal/session loss.
  • Foreground placement ≠ application readiness or correctness.

Quick reference

Job control in interactive shells:

long_task &          # run in background
jobs -l
Ctrl+Z               # stop foreground job (SIGTSTP)
bg %1                # continue in background
fg %1                # bring to foreground
disown -h %1         # don't send SIGHUP on logout
nohup ./task.sh > task.log 2>&1 &
systemd-run --user --unit=import ./import.sh   # transient unit, survives logout with lingering

Background jobs die with the SSH session (SIGHUP) unless nohup/disown, tmux/screen, or systemd-run is used. For anything important, run it as a service or inside tmux.

Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.

Limits and how it fails

Primary failure point. bg/fg shows a shell job-control transition, not daemonization, persistence after logout or service health.

ReferenceConfiguration & state1 section · depth on demand

Configuration, persistence and lifecycle

Distribution/platform context. bg / fg owns interactive shell job-control semantics. nohup, shell behavior and systemd services are adjacent but separate mechanisms.

Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Technical verification history

Verification history & basis

When and against what this Topic was checked. Later text edits do not count as a new check.

2026-09-14 · vendor doclinux current

Authoritative/upstream documentation reviewed for bounded claims in Processes → bg / fg. Documentation verification only; this is not observed lab or production Evidence.

Basis: https://gitlab.com/procps-ng/procps · confidence 94%
Technical changelog & impact

What changed and what may be affected

Recent technical edits are separated from ordinary page timestamps. Relationship impact is advisory: it identifies nearby canonical references to review, not automatic breakage.

Related reference impactReview these references after material technical changes when their shared boundary is affected.
Terminology layer

Terms & aliases

Hover a linked term for a quick definition; click it to open its glossary entry. Aliases are other names that find this Topic in search.

Aliases that resolve here
bg fg linuxlinux job controlforeground background jobsshell job control
Embedded reference data

Quick lookup tables

bg / fg operational reference

Topic-specific lookup boundaries, proof limits and next-step Evidence for bg / fg.

Lookup boundaryTopic-specific referenceOperational use
Scope / effective statebg and fg are shell job-control operations that continue a stopped job in the background or bring a shell-managed job to the foreground; they operate on the shell job table, not on arbitrary system services.Establish exactly what this Topic owns before crossing into another subsystem.
Fast verificationPin host/container + timestamp → identify exact process or unit → capture PID plus start identity and cgroup/unit → resolve effective unit fragment + drop-ins → inspect dependency/order transaction → record systemd job result → verify process/cgroup and active/sub state → prove application readiness → repeat the original workload test.Use the shortest evidence path first; a fast check is a boundary test, not blanket proof.
Verification chaininteractive shell → job/process group → stopped/running state → bg or fg transition → terminal foreground process group → signal/TTY behavior → workload resultTrace requested/configured state through effective state to the observed workload result.
Failure boundarybg/fg proves a shell job-control transition, not daemonization, persistence after logout or service health.Stop broad troubleshooting at the first boundary that is not supported by evidence.
Positive evidenceCorrelated Linux process/systemd evidence can establish this proof path: interactive shell → job/process group → stopped/running state → bg or fg transition → terminal foreground process group → signal/TTY behavior → workload resultUse this observation only for the specific claim it actually supports.
Evidence limitIt does not independently prove behavior outside the captured process, manager, unit, dependency, runtime or application scope. bg/fg proves a shell job-control transition, not daemonization, persistence after logout or service health.Do not promote a local success signal into end-to-end or adjacent-dependency proof.
Next troubleshooting checkContinue from the first unproven boundary: reacquire stable process identity, inspect effective loaded unit configuration and dependency/job state, correlate process/cgroup plus journal evidence, then run the original readiness/workload test before changing additional settings.Continue to the next unresolved boundary while preserving the original test condition.

bg / fg · operational reference

Compact Linux state, persistence, verification and boundary reference for fast lookup.

Reference boundarybg / fg
Topic pathProcesses → bg / fg
Runtime statebg and fg are shell job-control operations that continue a stopped job in the background or bring a shell-managed job to the foreground; they operate on the shell job table, not on arbitrary system services.
Fast checks- Confirm the exact interactive shell and its current job table. - Map shell job ID to the actual process group/PIDs before signaling or troubleshooting. - Check controlling TTY/session and whether logout/HUP behavior matters. - Use a service manager or deliberate detachment mechanism when persistence is required, then verify the workload independently.
Verification chaininteractive shell → job/process group → stopped/running state → bg or fg transition → terminal foreground process group → signal/TTY behavior → workload result Boundary chain: local authoritative state → adjacent dependency → effective/programmed state → original workload/request → return/regression → explicit Evidence boundary.
Failure boundarybg/fg proves a shell job-control transition, not daemonization, persistence after logout or service health. Boundary chain: process/context → userspace configuration → kernel subsystem/resource → device/network/filesystem dependency → effective state → original workload.
Persistence ruleProve which configuration source owns the state, then prove that the running consumer loaded or generated the intended state.
Confirmation

Confirm action

Continue?