Signals and graceful termination
Quick answer
Signals notify processes about events. Prefer a cooperative termination request such as TERM, allow cleanup time, and use only a verified target.
Prepare the practice environment
Use an ordinary user in an authorized disposable Linux VM. From the extracted package root run python3 lab-fixtures/processes/setup.py, enter its printed path and check pwd. Run each executable example in a fresh Bash process with LC_ALL=C and set -o pipefail. Do not use sudo. For interactive examples use a fresh interactive Bash and enter one command at a time. Signal only the just-started bounded child, never an arbitrary PID. Wait for completion before discarding the private workspace. Skip absent tools.
How it works
kill sends a signal; its success means delivery was accepted, not that cleanup finished. TERM can be handled or ignored; INT commonly requests interruption; HUP relates to hangup and is sometimes interpreted as reload by specific programs. KILL and STOP cannot be caught or ignored. A stopped task is not necessarily terminated. For Bash, wait commonly reports 128 plus the signal number when a child is terminated by a signal; applications can also return such numbers deliberately. timeout can bound a command, normally sending TERM at its deadline; it is not a universal process-tree sandbox. pkill selects by pattern and can affect multiple processes; inspect matches rather than use it for this lab. Do not escalate privileges or send signals to unrelated tasks.
A successful signal request and a successful shutdown are separate observations. A cooperative child can handle TERM, finish its cleanup and return status zero; another child may terminate with a signal-related status. GNU timeout normally returns 124 when its deadline expires, but an application could return that number itself, so preserve the surrounding evidence rather than diagnosing from one number. Keep deadlines bounded, signal only the child started in this fixture and collect its final status before declaring recovery complete.
Try the examples
sleep 3 &child=$!kill -TERM "$child"if wait "$child"; then printf 'completed\n'; else printf 'status=%s\n' "$?"; fiOnly the just-started child is signaled. Bash reports 143 for TERM on this Linux fixture; status is not a universal proof of signal cause.
Expected stdout:
status=143if timeout 0.1 sleep 1; then printf 'completed\n'; else printf 'status=%s\n' "$?"; fiGNU timeout reports 124 when its deadline expires without --preserve-status in this example.
Expected stdout:
status=124A command that finishes before its deadline can return its own successful status.
Expected stdout:
within deadlineCommon mistakes
Never use kill -9 as a routine first response, or pkill on a broad name. Do not copy a PID from another session. Capture a fresh child and keep its lifetime bounded.
Practice
Run the bounded timeout example with a duration longer than the sleep and one shorter. Explain the two statuses. Discuss why TERM allows cleanup but KILL does not.
Related references
Study: kill, pkill, timeout. These are reference names, not deployed links.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Signals and graceful termination — Knowledge Check
Apply process lifecycle and job-control concepts to a bounded child-process lab.
Which signal normally requests graceful termination?
Which cannot be caught?
What is the usual GNU timeout status when time expires?
Does successful kill prove exit?