ch05/l02

Jobs and foreground control

Understand shell-managed background work before losing track of it.

jobs 15 min read, 20 min lab operator

A shell can suspend, background, foreground, and list jobs it started. This is local to that shell session, not the whole system process table.

In the field

You accidentally suspended a foreground command and need to recover control.

Worked command

$ sleep 300 &$ jobs$ fg %1# Ctrl-Z suspends$ bg %1
Anti-pattern

Do not confuse shell jobs with all system services.

Safer pattern

Use `jobs` for your shell, `ps` for the system.

Knowledge check

In your shell `jobs` prints nothing, yet `ps aux` lists dozens of processes. Why?

  • A ps is stale and cached; jobs reflects the real, current process table
  • B jobs lists only jobs this shell session started; ps shows the whole system
  • C Those processes are zombies, which jobs deliberately hides
  • D Background jobs always disappear from jobs once they keep running
Show the answer

Correct: B. jobs lists only jobs this shell session started; ps shows the whole system

Why

jobs is scoped to the current shell's own job table, while ps reads the system-wide process table — so a quiet jobs list says nothing about other users, daemons, or other shells. Assuming ps is stale inverts the relationship; ps is the system view, not the unreliable one.

Practice checklist

  1. Start a background sleep.
  2. List it with `jobs`.
  3. Bring it foreground and stop it cleanly.

Deliverable evidence

  • A transcript showing jobs, fg, bg, and cleanup.
Teaching diagramch05 · mental model
symptom -> evidence -> least-invasive action symptom slow / full / stuck which class? CPU mem disk inode uptime CPU / load free -h available mem df -h disk bytes df -hi inodes narrow it: du -sh, pgrep -a, ps aux name the busy process or constraint TERM before KILL, only after evidence no blind restart

shows: The triage path: a symptom sorts into a resource class (CPU, memory, disk bytes, inodes), each with its own first command, then narrows to a named process or constraint before any TERM/KILL or restart.

does not prove: It shows the order of checks, not the verdict: running these commands gathers evidence but does not by itself prove which resource is the true bottleneck — you still have to read the numbers and reason about available vs free, bytes vs inodes.

Memorize this

Commit these to memory, then drill them until recall is automatic.

jobsfgbgCtrl-Z&
Recall practice · Scenario -> next check

cue A command is suspended (you hit Ctrl-Z); resume it in the background as job 1

show recall target

bg %1