fg is a shell builtin that resumes a stopped or background job, putting it back in the foreground attached to the terminal. It is the counterpart to Ctrl-Z (which stops the current job) and bg (which resumes a stopped job in the background).
sleep 1000 # run a long-running command
# press Ctrl-Z to stop it
jobs # list shell jobs
fg # resume the most recent job
fg %2 # resume job 2
bg # resume in the background instead
Job control is a shell feature, not a kernel one: the shell tracks its child processes and their states. fg, bg, jobs, and disown only make sense inside an interactive shell with job control enabled (the default for bash, zsh, fish).
Related terms: bg, jobs, disown, nohup
Discussed in:
- Chapter 10: Processes and Job Control — Job Control