A program is an executable; a process is one running instance of a program. Two people can start the same program, and one person can start it twice. The name alone does not tell you which instance belongs to your task.
You will start a short, harmless wait, capture its actual process ID, and inspect its owner, parent, start time, arguments and state. A second wait will let you compare two real histories. Both processes finish naturally; this lesson sends no signals and creates no files or directories.
1. Read a process snapshot as evidence
A PID identifies a process while that process exists. A PPID identifies its parent. Numeric IDs can later be reused, so a saved number is not a permanent identity or permission to act on whichever process has it now.
For these controlled commands, compare several fields together:
Field selected with ps -o | What to inspect |
|---|---|
pid | The number captured from your actual launch. |
ppid | The current interactive Bash shell that launched the child. |
euid | The effective numeric owner, matching your ordinary guest UID. |
stat | A scheduling state followed by possible status modifiers. |
lstart | The displayed process start date/time, recorded as observed. |
args | The displayed command and duration arguments. |
ps reports a snapshot; it does not reserve a PID or guarantee what exists
by the time you read another line. Displayed arguments can also be incomplete
or truncated. Treat missing fields and unexpected metadata as incomplete
evidence, not as a reason to guess an identity.
A waiting sleep commonly has state S, meaning interruptible sleep.
R means running or runnable; it is not required for a live process. Extra
characters can qualify the state; for example + marks membership of the
terminal's foreground process group. Background execution describes the
shell's waiting behavior, while S describes the process's current scheduling
state. They answer different questions.
2. Establish the ordinary interactive shell
Goal: identify only processes launched for this task, compare their actual
identity evidence, then observe natural completion. Use the verified Ubuntu
guest's ordinary Bash terminal. No sudo, listener, profile edit or filesystem
fixture is needed; an unused ~/linux-practice/ directory would add nothing
to this exercise.
Run one line at a time and read each result. Begin with the taught identity, active-shell and command-origin checks:
id -u
ps -p $ -o comm=
type -a printf set declare unset wait ps sleep id
Require the expected nonzero ordinary UID and Bash. printf, set, declare,
unset and wait must be Bash builtins. Require the distribution's external
ps, sleep and id, with no unexpected alias/function/command origin.
The launch below uses the inspected /usr/bin/sleep path explicitly:
type -P sleep
Require /usr/bin/sleep. Reconcile a different baseline without changing PATH.
The special Bash parameter $- contains letters describing active shell
options; its i letter identifies an interactive shell. This is a read-only
observation, not an assignment:
printf 'Shell option letters: %s\n' "$-"
Require the i letter. Do not run the task inside a script or a child shell
whose parent relationship you have not established. Use the already taught
read-only option list:
set -o
Require allexport off so the two practice variables stay local, and errexit
off for expected absent-variable/process observations. Keep other settings
unchanged; preserve and reconcile a differing baseline rather than setting
options for this task.
Prove both task variable names absent before either assignment. Named
declare -p reveals local and exported variables, including empty values,
readonly attributes and name references:
declare -p VECTA_LAB_PROCESS_ONE_PID
declare -p VECTA_LAB_PROCESS_TWO_PID
Each must report an absent/not-found name. Any declaration is a collision; leave it intact and stop. Do not unset a preexisting name to make room.
Record your real shell PID and ordinary effective UID for later comparisons.
$ is the current Bash process's PID in this interactive context.
ps -p PID selects only the specified PID, while -o selects the output
fields listed in the earlier table. The comma-separated words after -o
are field names, not process names. Use that format for the shell first:
printf 'Launching shell PID: %s\n' "$"
id -u
ps -p "$" -o pid,ppid,euid,stat,lstart,args
Require the row to identify this Bash shell under your recorded UID. Do not add a user selector such as -u to
“make it safer”: ps selection criteria can combine by addition, showing
extra processes instead of restricting the PID to that user. Inspect euid
in the selected row.
3. Launch one bounded wait and capture its actual PID
GNU sleep 180 waits for the requested 180 seconds, then normally exits.
Scheduling can affect precisely when you observe completion. No file input,
network listener or persistent service is involved.
A trailing & asks Bash to start the command asynchronously and return to
the prompt without waiting for completion. Bash may print a bracketed job
number and a PID. The job number is shell bookkeeping; use the actual PID
capture below rather than copying a guessed number from an example.
Bash's $! is the PID of its most recently started asynchronous command.
For this one external command, capture it immediately after launching, before
starting any other background work. The assignment has no spaces around =
and uses the task name already proven absent.
Read this whole pair first, then enter its two lines in order without another background launch between them:
/usr/bin/sleep 180 &
VECTA_LAB_PROCESS_ONE_PID=$!
If the launch prints an execution error or another unexpected diagnostic, stop before treating the value as a successfully started sleep. The shell's asynchronous launch status alone cannot prove successful execution or continued existence. Now inspect the captured value and selected process:
printf 'First captured PID: %s\n' "$VECTA_LAB_PROCESS_ONE_PID"
Require a nonempty numeric capture before using it as a selector. Only then:
ps -p "$VECTA_LAB_PROCESS_ONE_PID" -o pid,ppid,euid,stat,lstart,args
Require a complete row for the expected /usr/bin/sleep 180 command. Its PPID must match the recorded Bash PID; its
EUID must match your ordinary UID. Record the observed start time, arguments
and state with that PID. A state beginning with S is a normal observation
for this waiting command. Do not demand an invented PID, timestamp or exact
status suffix.
The evidence needs to agree as a set. A row for the wrong owner, parent, start history or command is not “close enough” because its name includes sleep. If output is truncated, the observation is incomplete; revisit the supported display/help guidance rather than filling in missing arguments.
Inspect again without creating a replacement
Before the requested duration expires, inspect the same selected PID again:
ps -p "$VECTA_LAB_PROCESS_ONE_PID" -o pid,ppid,euid,stat,lstart,args
While the original process remains alive, its owner, parent, start history and command should agree with the first record. Its scheduling state is an observation that may change. A terminal completion notification may appear when the process exits; that is normal shell bookkeeping, not a new launch.
If you took longer than the duration, no selected process row is an honest result. The header may remain, and ps may return a nonzero no-match status. Do not silently start another sleep or overwrite the captured PID to make an expected row appear. Keep the completed process's record and follow the natural-completion check below. A later row with changed identity may indicate PID reuse or a recording mistake; never act on it as if it were the old child.
Diagnose observation before action
| Observation | Explanation or next evidence |
|---|---|
| Several processes share the same program name. | Compare captured launch history, PID, owner, parent, start and arguments. |
A live sleep shows S, not R. | It is waiting; a process need not be using the CPU to exist. |
| The captured PID has no row. | The bounded duration may have elapsed, or launch failed; use the launch history and named wait. |
| A row has the wrong owner/parent/command. | Stop identifying it as yours; a stale or mistaken number is insufficient. |
| The expected arguments are cut off. | Evidence is incomplete; do not assume the hidden text. |
| A saved PID comes from another terminal or older attempt. | It lacks this shell's current launch history; do not use it as an action target. |
Independent task: compare a second launch
Start a second /usr/bin/sleep with a requested duration of 120 seconds.
Capture its PID immediately in the second name already proven absent,
VECTA_LAB_PROCESS_TWO_PID. Before launching, explain which ps fields you
expect to match the first record and which can distinguish the new instance.
Use only the taught asynchronous launch, capture and PID-selected inspection.
Record the second process's actual PID, PPID, EUID, state, displayed start and arguments. Compare the second record with the first without relying on the shared program name. While both processes exist simultaneously, their PIDs must differ; PPID and EUID should match the same launching shell and user. The chosen duration arguments also differ.
The first process may already have finished. In that case, compare its saved record with the new observation and explicitly label the first as historical; do not claim both are currently alive or quietly replace its saved PID. A new process can eventually reuse an old number. Its current evidence must still be tied to its own launch history.
For this task's successful two-record comparison and later two-wait sequence, require the captured numbers to differ even when the first record is already historical. If they are equal, preserve the ambiguity and use the equal-capture branch in the completion guidance; do not report two separately checked child completions or silently replace either number.
Success: both records identify your actual launches with complete metadata, you distinguish current and historical observations, and you explain why a matching name or copied PID would not be sufficient evidence for a later termination decision. No termination command is used here. Try the task before opening the graduated hints and answer.
Hint 1
Capture $! immediately after the second asynchronous command. Use the
second collision-checked name; preserve the first process's history.
Hint 2
Select with -p and display the same six fields. Compare owner and parent
with the recorded shell baseline, not merely with the other sleep's name.
Hint 3
The second duration is 120. A different launch record and different duration
help distinguish the instances, even if an earlier PID has since disappeared.
Shared owner and parent are expected and do not mean the processes are identical.
Answer and Reasoning
After confirming the second name remains absent and the shell baseline is unchanged, one valid independent launch/capture pair is:
/usr/bin/sleep 120 &
VECTA_LAB_PROCESS_TWO_PID=$!
Stop on a launch diagnostic before calling this a successful process. Inspect the actual capture, then its complete selected row:
printf 'Second captured PID: %s\n' "$VECTA_LAB_PROCESS_TWO_PID"
Require a nonempty numeric capture before the selected inspection:
ps -p "$VECTA_LAB_PROCESS_TWO_PID" -o pid,ppid,euid,stat,lstart,args
Expect the recorded shell PPID and ordinary EUID, the newly captured PID,
an observed start time and /usr/bin/sleep 120 arguments. Record what appears,
including state; no fixed numbers or timestamp are supplied as fake output.
The first process used duration 180. Same program and owner do not erase
the distinct launch histories. A PID can be reused after a process ends,
so neither a copied number nor a matching name proves persistent identity.
Allow completion and check only the named children
Bash wait PID waits for a specified child known to this shell and returns
its completion status. It does not send a termination signal. It may return
immediately if that recorded child already finished. This is different from
waiting for every shell child: always supply this task's captured PID.
Use each line only for a name you actually assigned from the corresponding launch in this same shell, with the recorded value unchanged. The two-wait sequence also requires distinct captured numeric values.
If the values are equal, do not use the first wait as evidence about the
original first child: that numeric operand could now refer to the second.
Keep the attempt's ambiguity in your record. If the second launch has been
positively identified from its actual capture and complete 120-second
process evidence, its named wait may establish only the second child's
completion; it does not recover a separate first-child status. Allow the
bounded launches to finish, reconcile the current-child identity, and repeat
from a fresh baseline after clearing only your owned captures. Do not count
that ambiguous attempt as the successful two-completion check. If even the
current identity cannot be established, retain that uncertainty and allow
natural expiry without acting on the number.
For the normal, distinct-capture case, check the first child:
wait "$VECTA_LAB_PROCESS_ONE_PID"
printf 'First completion status: %s\n' "$?"
The prompt can pause while the remaining requested wait completes. For the
normal successful sleep, expect status 0. A “not a child” result, launch
failure or unexpected status requires diagnosis; it is not proof of a
successful normal completion. Do not substitute a copied PID from elsewhere.
After completing the independent launch, check the second child separately:
wait "$VECTA_LAB_PROCESS_TWO_PID"
printf 'Second completion status: %s\n' "$?"
Again require the expected successful natural completion. Inspect the two saved numbers after those checks:
ps -p "$VECTA_LAB_PROCESS_ONE_PID" -o pid,ppid,euid,stat,lstart,args
ps -p "$VECTA_LAB_PROCESS_TWO_PID" -o pid,ppid,euid,stat,lstart,args
Normally there are no matching rows. If a number now selects an unrelated process, record the changed identity and leave it alone; do not claim global PID absence or treat that row as your completed sleep. The known child's wait result and its recorded history establish completion of your original task. No signal is needed to tidy a stale number.
Cleanup and a deliberate rerun
Only after both actually launched children have completed and their outcomes
are reconciled, remove the two task variables you created. The taught
unset -v removes variables rather than same-named functions:
unset -v VECTA_LAB_PROCESS_ONE_PID VECTA_LAB_PROCESS_TWO_PID
If a launch was never performed, leave that absent name alone and clear only the name you actually assigned after its child finishes. No directory, file, shell option, PATH value or profile needs restoration.
To repeat a comparison missed through natural expiry, finish and inspect the known children, clear only the owned captures, then repeat all starting-state and absence checks. Label the new attempt separately. Do not overwrite an old record while an earlier child may still exist.
After interruption or a new terminal, do not treat remembered PIDs as current children of the new shell. The original bounded sleeps need no signal to finish. Reconcile their recorded history, allow their requested durations to elapse, and begin a fresh attempt only from a known baseline. If identity, launch success or completion remains uncertain, preserve that uncertainty rather than searching by name and acting on another process.
Sources and other study views
- S18 — Bash: asynchronous commands, special parameters and wait
- S19 — GNU Coreutils: bounded sleep duration
- S25 — Ubuntu Noble ps: selection and displayed process fields
The selected guest uses Bash 5.2, GNU Coreutils 9.4 and Noble procps. Upstream manuals may cover other releases; this task uses the bounded syntax above and requires actual observations from your own launches.
Revision reconstructs the evidence model; Quick Reference retrieves the commands and conditions.