background job
A command started with & at the end of the line, which runs while the shell immediately gives you the prompt back.
In more detail
The shell prints its job number and process ID, and $! holds that process ID. Output from a background job still appears on your terminal unless redirected. In a script, wait pauses until background jobs finish.
Examples
sleep 30 &The ampersand is a request to the shell, not a property of the program. A background job is still tied to the terminal session and usually ends when you log out, because of the hangup signal. Backgrounding changes interaction, not reliability.Related terms
- 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.
- wait builtin — The builtin that pauses a script until its background jobs, or one given job or process, have finished.
- process ID — The number the kernel gives each running process so it can be told apart from all the others.
- foreground job — The job that currently owns the terminal's input, so the shell waits for it before showing the prompt again.
- nohup — A command that runs another command immune to the hangup signal, so it keeps running after you log out.
- SIGHUP — The hangup signal, sent to programs when the terminal they were started from closes.
Taught in
- Processes, Jobs And Signals — Bash Scripting & Command Line Automation
- Job Control, And Processes That Outlive You — Linux Fundamentals & Systems Administration