Pcornel
Linux · Processes

bg / fg

Cheat sheet · https://pcornel.dk/topic.php?topic=2716

Back to the Topic

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.

Remember

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).

First 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

Verify in this order

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

Where it usually breaks

First mismatch in hardware/kernel capability → scheduler/mm/device → cgroup/namespace → process/thread → service/runtime → workload behavior/counters; preserve identity/native diagnostic/pre-state before mutation.

Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=2716

Confirmation

Confirm action

Continue?