Use it to manage several tasks in one terminal, or to keep a long task running after logout.
bg / fg
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.
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>.
command started (fg or &) → Ctrl+Z stops it → bg/fg resume it → terminal hangup kills it unless detached
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
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
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 · 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.
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).
jobs -l— jobs with PIDs and statefg %1— bring job 1 to the foregroundbg %1— resume job 1 in the backgroundnohup <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.
jobslists the shell's jobs.bgresumes a job in the background, andfgbrings it to the foreground.%nrefers to job number n,%stringto a job whose command starts with the string, and%?stringto 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
| Action | Command |
|---|---|
| Start in the background | long-task & |
| Suspend the foreground job | Ctrl-Z |
| Continue in the background | bg or bg %2 |
| Bring to the foreground | fg or fg %1 |
| List jobs with PIDs | jobs -l |
| Wait for background jobs | wait or wait %1 |
| Keep running after logout | disown -h %1, nohup cmd & |
| Kill a job | kill %1 |
Surviving logout: which tool
| Tool | When |
|---|---|
nohup cmd > out.log 2>&1 & | Quick one-off; ignores SIGHUP |
disown | A job that's already running |
tmux / screen | Interactive work you want to reattach to later |
systemd-run --user --unit=job cmd | Logged, controllable, survives the session (with lingering) |
| A proper service unit | Anything 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.
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.
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
Verification history & basis
When and against what this Topic was checked. Later text edits do not count as a new check.
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%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.
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.
Quick lookup tables
bg / fg operational reference
Topic-specific lookup boundaries, proof limits and next-step Evidence for bg / fg.
| Lookup boundary | Topic-specific reference | Operational use |
|---|---|---|
| Scope / effective state | 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. | Establish exactly what this Topic owns before crossing into another subsystem. |
| Fast verification | Pin 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 chain | interactive shell → job/process group → stopped/running state → bg or fg transition → terminal foreground process group → signal/TTY behavior → workload result | Trace requested/configured state through effective state to the observed workload result. |
| Failure boundary | bg/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 evidence | Correlated 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 result | Use this observation only for the specific claim it actually supports. |
| Evidence limit | It 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 check | Continue 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 boundary | bg / fg |
|---|---|
| Topic path | Processes → bg / fg |
| Runtime state | 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. |
| 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 chain | interactive 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 boundary | bg/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 rule | Prove which configuration source owns the state, then prove that the running consumer loaded or generated the intended state. |