Sending a request and observing its result are different steps. A successful
kill command does not prove that its target exited, and an exited process
does not prove that an application saved its work. This lesson uses a small
owned sleep so you can separate those claims without touching another process.
You will request termination of one newly captured sleep, inspect its actual completion result, then stop, continue and terminate a second fresh sleep. Only the individually verified positive PIDs from these launches are targets. There are no files, listeners, sudo commands or changes to shell settings.
1. Choose a signal for the intended operation
A signal is a notification to a process. A process can handle or ignore some signals, while others have kernel-enforced effects.
| Signal | Meaning for this lesson |
|---|---|
TERM | Request termination. Applications can arrange handling/cleanup; the ordinary sleep's default action is termination. |
STOP | Suspend execution; the target cannot catch, block or ignore this signal. |
CONT | Continue a stopped process. |
KILL | Force termination without an application handler; discussion only, no KILL command in this exercise. |
TERM gives an application a chance to handle a shutdown request when it has appropriate handling. It does not promise that cleanup happened. KILL also cannot be caught, blocked or ignored, so it cannot run the application's normal signal handler to save state. A stronger request needs a specifically verified owned target, a reason the ordinary shutdown is insufficient, and an understood consequence. It is not a routine response to an unclear result. The simple sleep in this exercise needs no KILL escalation.
The Bash builtin form kill -s SIGNAL -- PID selects a signal name with -s;
-- ends options before the target. Use one actual positive PID, never zero,
a negative number, an unrelated PID or a process-name sweep. The name kill
does not imply every signal terminates a process: STOP and CONT demonstrate
that distinction.
Read the two statuses as different evidence
The status immediately after kill describes the sending request. A
zero result means the request was accepted for the selected target; it is
not the target's completion status.
Bash wait collects a known child's result. With job control, ordinary wait
can return on a state change, as the preceding lesson showed. Here wait -f PID adds -f to wait for termination rather than an intermediate job
state change. Use it only after a stopped owned child has been continued and
checked non-stopped, or after its actual completion is established. Otherwise
a wait for termination can sit behind a child you have left suspended.
Bash reports a signal-terminated child as 128 + signal number. A nonzero
result can therefore be the expected evidence of this exercise, not a failed
lesson. The read-only kill -l TERM asks for TERM's number; -l is a lookup
here and sends no signal. We will inspect that number in the actual guest
before interpreting the result.
2. Establish the original shell and absent captures
Goal: act only on the two recorded practice lifetimes, verify each actual state/outcome and leave no owned process active or stopped. Use the checked ordinary nonzero Ubuntu guest user and the original interactive Bash terminal. No unused practice directory is needed.
Run one line at a time and read every result before the next action:
id -u
ps -p $ -o comm=
type -a printf set declare unset jobs wait kill ps sleep id
Require the expected UID and Bash, the known Bash builtins and distribution ps/sleep/id, with no unexpected alias, function or command origin. Confirm the actual sleep path and the earlier interactive/job-control conditions:
type -P sleep
printf 'Interactive shell flags: %s\n' "$-"
set -o
jobs -l
Require /usr/bin/sleep, i in the shell flags, monitor on,
allexport/errexit off and an empty job table. Preserve different settings
and unrelated jobs; reconcile the baseline rather than clearing or changing
them for this task.
Before either assignment, prove both names absent:
declare -p VECTA_LAB_SIGNAL_PID
declare -p VECTA_LAB_SIGNAL_SECOND_PID
Each must report absent/not found. Any declaration, including an empty, readonly or name-reference value, is a collision to preserve. Record the current shell identity and signal-number observation:
printf 'Launching Bash PID: %s\n' "$"
id -u
ps -p "$" -o pid,ppid,euid,stat,lstart,args
kill -l TERM
The selected Linux environment normally reports TERM as 15, giving an
expected Bash signal-completion status of 143 (128 + 15). Record the actual
lookup. An unexpected result needs reconciliation before sending signals;
do not substitute an unexplained number. Use signal names in the sending
commands even though you inspect the number for result interpretation.
3. Start a bounded sleep and prove its current identity
Use the already taught background launch and immediate capture, with no intervening background command:
/usr/bin/sleep 240 &
VECTA_LAB_SIGNAL_PID=$!
A launch diagnostic blocks any claim that this is a successful sleep. Print the actual capture and require a nonempty positive numeric PID:
printf 'Guided PID: %s\n' "$VECTA_LAB_SIGNAL_PID"
Then inspect the actual job and selected process:
jobs -l
ps -p "$VECTA_LAB_SIGNAL_PID" -o pid,ppid,euid,stat,lstart,args
Require one active owned job with that PID; its PPID must match the recorded
Bash PID and its EUID your ordinary UID. Require the expected
/usr/bin/sleep 240 arguments and record its observed start time. State S
is normal for a waiting sleep. Match the complete launch history, not only
a name or number. Truncated fields, unexpected ownership, a different parent
or inconsistent start/arguments mean you lack sufficient identity evidence.
If the sleep already ended, do not signal its stale number. Follow the natural-completion branch below, settle this child's result and start a separately recorded fresh attempt if needed. A PID can be reused after exit.
Recheck immediately before TERM
Predict that TERM will end this ordinary sleep, while the request's status and the child's completion status will describe different events. Immediately before the signal, inspect again:
jobs -l
ps -p "$VECTA_LAB_SIGNAL_PID" -o pid,ppid,euid,stat,lstart,args
Require that same live, non-stopped owned child, including owner, parent, start and arguments. If it is absent or a row has changed, do not send TERM. These snapshots do not freeze a PID; the child can still exit between inspection and the request. Interpret the actual sending and completion results rather than automatically retrying on the old number.
Only after the identity check agrees:
kill -s TERM -- "$VECTA_LAB_SIGNAL_PID"
printf 'TERM request status: %s\n' "$?"
Record the request status immediately. A zero result supports that the request was accepted; it does not establish exit or application cleanup. An error such as no such process may mean natural expiry raced the request. Stop sending, retain the diagnostic and inspect the actual child history; do not escalate against a possibly stale PID.
Collect actual termination and inspect the remaining state
For this known child of the original shell, after it is non-stopped or already
completed, collect termination with the taught -f option:
wait -f "$VECTA_LAB_SIGNAL_PID"
printf 'Guided child completion status: %s\n' "$?"
jobs -l
ps -p "$VECTA_LAB_SIGNAL_PID" -o pid,ppid,euid,stat,lstart,args
For the intended TERM result on the selected Linux baseline, expect 143,
not ordinary-success 0. Require no original live/stopped job or process;
observe any completion notification before requiring the job table empty.
Bash may display a termination message as part of that notification. Its
wording is not the evidence by itself.
If the result is 0, record normal sleep completion; that does not demonstrate
TERM termination. If it is another signal-derived value, record the different
outcome and diagnose it. A 127/unknown-child result is not a recovered child
exit status: preserve that uncertainty and reconcile the original shell and
capture rather than presenting it as the intended signal result.
If a later ps row uses the old number for a different process, leave that process untouched. Your original child's recorded result and launch history do not make a reused number an authorized target.
Guided success: a verified request, the expected TERM-derived child result and the absence of the original process agree. This proves what happened to the simple sleep; it proves nothing about an unrelated application's data flush or cleanup routine.
If the child completed naturally before the request
Skip TERM when the original child is already absent. In the original shell,
use its named wait -f and immediate result, then jobs/ps, to settle the actual
outcome. Normal expiry should give 0; unknown-child or mismatched evidence
remains a diagnostic issue. If TERM evidence was missed, finish this attempt
and clear only its owned capture before repeating the full launch/identity
checks with a new sleep. Never overwrite the old PID record while its outcome
is unresolved.
After the guided child is fully reconciled and the job table is empty, remove only this task's guided capture with the taught variable-removal command:
unset -v VECTA_LAB_SIGNAL_PID
Complete that lifecycle before the independent launch, so a reused number cannot confuse two later wait claims about different children.
Diagnose before considering a stronger action
| Observation | What it supports or requires |
|---|---|
kill returned zero. | The sending request was accepted; inspect child completion/state separately. |
Named wait returned 143 after TERM. | Expected signal-derived termination on the checked TERM=15 baseline, not ordinary exit zero. |
Named wait returned 0. | Normal completion; do not label it proof that TERM terminated the child. |
| The recorded PID is absent or identifies another process. | Do not send or retry a signal to that number. |
| A child remains stopped. | Its normal sleep execution cannot finish while stopped; reverify and continue the owned child before using wait -f for termination. |
| A program is still present after a request. | Recheck identity and behavior. A stronger signal is not justified by uncertainty alone. |
Independent task: continue a stopped child, then request its exit
Start from an empty original job table with the guided capture cleared and
VECTA_LAB_SIGNAL_SECOND_PID still absent. Use a new /usr/bin/sleep with a
requested duration of 180 seconds, and capture its actual PID immediately
in that second name. Record its complete positive-PID/owner/parent/start/args
identity before creating the controlled stopped condition.
Know recovery before STOP: the existing signal form with CONT continues
only this same freshly verified positive PID. Keep the original prompt and
record. A stopped finite sleep will not finish its normal wait just because
its requested time passes; it must be continued. If identity is uncertain,
do not signal a guessed match. Reconcile the current child before leaving.
Predict the three observations before acting: stopped state after STOP, continued state after CONT, and the child's result if a later TERM actually terminates it. Use a fresh jobs/ps identity check immediately before each STOP, CONT and TERM request, and record each sending status immediately. Observe the corresponding process state after the request.
After STOP, require the same child stopped (T). Reverify it before CONT.
After CONT, inspect again: it may still be active, or it may complete naturally
because its requested wait elapsed while stopped. In that latter case, do
not send TERM to its former PID. Collect and label natural completion, then
start a separately recorded new attempt if needed to demonstrate the full
CONT-then-TERM outcome.
Only a still-live, freshly verified, non-stopped child is eligible for the
planned TERM. Collect its actual termination with named wait -f, interpret
the status and verify no original active/stopped job remains. No KILL, sudo,
process group or name-based selection is required.
Success: STOP and CONT state evidence, the expected TERM completion when performed, and final original-process absence match the recorded identity. Explain why request acceptance alone cannot prove application cleanup, and why the simple controlled sleep needs no KILL escalation. Try before the hints.
Hint 1
The resume signal is CONT. Restore execution before waiting for a stopped child's normal completion or sending the planned TERM.
Hint 2
The same captured number is usable only while fresh owner/parent/start/command evidence still identifies the same child. Check the post-CONT state before deciding that a TERM target remains.
Hint 3
Keep three records separate: sending status, current jobs/ps state and actual
child completion status. On this TERM=15 baseline, expected TERM termination
is 143; normal expiry is 0. Neither value proves application cleanup.
Answer and Reasoning
A valid fresh launch/capture is:
/usr/bin/sleep 180 &
VECTA_LAB_SIGNAL_SECOND_PID=$!
Stop on a launch diagnostic. Print/check the positive capture and establish its actual start record:
printf 'Independent PID: %s\n' "$VECTA_LAB_SIGNAL_SECOND_PID"
Only after the capture is a positive numeric value:
jobs -l
ps -p "$VECTA_LAB_SIGNAL_SECOND_PID" -o pid,ppid,euid,stat,lstart,args
Require the expected same-shell ordinary owner and /usr/bin/sleep 180
arguments. After a fresh matching inspection, apply the planned stop:
kill -s STOP -- "$VECTA_LAB_SIGNAL_SECOND_PID"
printf 'STOP request status: %s\n' "$?"
jobs -l
ps -p "$VECTA_LAB_SIGNAL_SECOND_PID" -o pid,ppid,euid,stat,lstart,args
Require the same child in stopped state. If a snapshot arrives before the transition, reread the read-only observations rather than blindly resending signals. An unexpected identity or unresolved state blocks further action. With the stopped child's identity freshly confirmed, continue it:
kill -s CONT -- "$VECTA_LAB_SIGNAL_SECOND_PID"
printf 'CONT request status: %s\n' "$?"
jobs -l
ps -p "$VECTA_LAB_SIGNAL_SECOND_PID" -o pid,ppid,euid,stat,lstart,args
Require active non-stopped state or honest natural completion. If it completed, skip the next signal, collect the actual named completion and label that outcome; a new recorded attempt is needed for the full requested TERM evidence. Do not turn an expired PID into a new target.
For the still-active branch, recheck all identity fields immediately before TERM. Only then:
kill -s TERM -- "$VECTA_LAB_SIGNAL_SECOND_PID"
printf 'Independent TERM request status: %s\n' "$?"
Record that request separately. For the known non-stopped or completed child, collect its actual termination and inspect state:
wait -f "$VECTA_LAB_SIGNAL_SECOND_PID"
printf 'Independent child completion status: %s\n' "$?"
jobs -l
ps -p "$VECTA_LAB_SIGNAL_SECOND_PID" -o pid,ppid,euid,stat,lstart,args
Expected TERM termination is 143 under the observed TERM=15 mapping. A
normal-expiry branch instead returns 0; other outcomes require their own
explanation. -f avoids mistaking a mere stop-state change for termination,
but it is not a way to make a still-stopped process finish. CONT and observed
resumption must precede waiting in that situation.
The sleep ends under the ordinary TERM behavior, so forcing KILL would add no justified step. Its disappearance and wait status concern this child lifetime. They cannot show that an application saved a document, committed data or completed a custom shutdown handler.
Cleanup and resumption
Require no original owned process active or stopped and an empty jobs table after observing notifications. A numeric PID reused by a different process is not leftover course work; leave it alone. Clear only the independent capture you created after its outcome is reconciled:
unset -v VECTA_LAB_SIGNAL_SECOND_PID
The guided capture was already cleared after its separate lifecycle. If a launch never happened, do not create a variable just to clean it up. No file, shell setting or other job was changed.
On interruption, retain the original shell, recorded child lifetime and actual identity evidence. If the known owned child is stopped, freshly verify it and continue it through the taught CONT route; do not abandon it assuming its finite duration guarantees normal completion. If it completed, collect its known result where still available. A remembered number in a new shell is not automatically that shell's child and must never be treated as a safe signal target without the original evidence.
To rerun a missed or ambiguous outcome, first reconcile the old child, clear only its owned capture and repeat all empty-job-table/absent-name/identity checks. Keep unknown outcomes labelled unknown; do not invent cleanup evidence or send a stronger signal to remove uncertainty.
Sources and other study views
- S18 — Bash: named signals, signal numbers and wait termination results
- S19 — GNU Coreutils: the bounded sleep fixture
- S25 — Ubuntu Noble ps: selected process identity and state
- S73 — Linux signal companion: dispositions and signal effects
The selected environment is the declared Bash 5.2 Ubuntu guest with GNU Coreutils 9.4. The signal reference is a Linux man-pages 6.03 companion; your own signal lookup, process observations and child results supply the actual exercise evidence.
Revision reconstructs the three evidence layers; Quick Reference retrieves the bounded signal sequence.