job control
The shell feature for managing the commands it started: listing them with jobs, and moving them between foreground and background with fg and bg.
In more detail
A job is a command or pipeline your shell started, named with a percent sign and its number, such as %1. Control Z suspends the foreground job, bg lets it continue in the background and fg brings it back to the terminal. Job control is an interactive feature, but kill %1 and wait also work inside scripts.
Examples
sleep 30 &jobsfg %1The shell numbers each job in its job table, shown by jobs, and fg %1 or bg %1 move job 1. A job number only means something to that shell; other tools need the PID. Job control does not make a command durable: it changes how you interact with it, not whether it survives logout.job=1 pid=42 state=running terminal=shared shows a job number and PID for the same process.Related terms
- background job — A command started with & at the end of the line, which runs while the shell immediately gives you the prompt back.
- Control Z — The key combination that suspends the foreground job by sending it SIGTSTP, pausing it without ending it.
- kill — The command that sends a signal to a process or job, SIGTERM by default, despite its name.
- wait builtin — The builtin that pauses a script until its background jobs, or one given job or process, have finished.
- foreground job — The job that currently owns the terminal's input, so the shell waits for it before showing the prompt again.
- process group — A set of related processes, such as all the commands in one pipeline, that the shell and kernel can signal together.
- shell — The program that reads the commands you type, runs them and shows the results; sh and bash are common ones.
Taught in
- Help, History, Completion And Aliases — Bash Scripting & Command Line Automation
- Processes, Jobs And Signals — Bash Scripting & Command Line Automation
- Job Control, And Processes That Outlive You — Linux Fundamentals & Systems Administration
- The Reindex That Died With The VPN: Jobs, cron, at And Timers — CompTIA Linux+ (XK0-006) Exam Prep
- Processes: Priorities, Monitors And Long Jobs — LPIC-1 Linux Administrator (101-500 and 102-500) Exam Prep
References
- Bash Reference Manual: Job Control Basics
- Bash Reference Manual: Job Control Builtins
- man7: bash(1)
- POSIX Shell Command Language: job control