Terminal · intermediate
Foreground, background, and jobs
Interactive shell job control groups pipeline processes into jobs and manages which job owns the controlling terminal's foreground process group.
Why it matters
It lets a user pause, resume, background, and foreground work without confusing shell job identifiers with operating-system process identifiers.
Mental model
How to reason about foreground, background, and jobs
The terminal has one foreground process group allowed ordinary terminal interaction; the shell tracks jobs and transfers that foreground role as commands start, stop, or resume.
Analogy
A shared microphone can belong to one performing group at a time, while the stage manager tracks waiting and paused groups by separate job numbers.
Examples
See the boundary, not just the happy path
Worked example · Start a background job
long_report > report.txt 2>&1 && lets the interactive shell return a prompt while the job runs; redirecting its output prevents competing terminal writes.
Worked example · Pause and resume
Ctrl-Z, then bg %1, then fg %1The terminal stop character normally suspends the foreground job, and the shell built-ins resume job 1 in the background or foreground.
Useful contrast · Job ID versus PID
kill %1 versus kill 4242%1 is shell job notation and may identify a pipeline process group, while 4242 names one operating-system process ID.
Common mistakes
Misconceptions to remove early
Assuming & survives logout reliably
A background job can still retain terminal connections or receive hangup-related signals; persistent work needs an appropriate service manager, scheduler, or terminal multiplexer.
Expecting a background reader to use the terminal normally
Background process groups that attempt terminal input are normally stopped with SIGTTIN rather than sharing interactive input with the shell.
Quick check
Can you predict the result?
1. What does fg %1 do in a job-control shell?
- • It resumes or continues job 1 and gives its process group the terminal foreground.
- • It changes the job's PID to 1.
- • It writes the job's output to a file.
2. Why is a shell job ID not always interchangeable with a PID?
Keep building