Follow a process from start to stop
A first Linux lab: start a harmless command, inspect its identity, and observe its lifecycle.
Starter content: an introductory example for this new notebook, not a record of completed personal work.
The question
How does a shell identify a command it starts in the background?
Environment and scope
Use Bash in your own disposable Linux VM or local Linux lab. These are proposed steps, not output from an experiment already performed. The process IDs will differ on every machine. Avoid running experiments on production systems.
Try the experiment
Start a short-lived command and save the process ID immediately:
sleep 60 &
lab_pid=$!
printf 'Started process: %s\n' "$lab_pid"
ps -o pid,ppid,stat,comm -p "$lab_pid"
wait "$lab_pid"
printf 'Exit status: %s\n' "$?"
The command exits on its own after about a minute. wait observes completion and returns its exit status. Run these commands together in the same shell so the saved variable refers to that background job.
Record the evidence
- Your Linux distribution and shell version.
- The process ID and parent process ID shown by
ps. - The process state at the time of observation.
- The exit status returned after
wait.
Do not copy example process IDs into a write-up as though you observed them. Keep your actual command output and explain what each field means.
The next question
What changes when the command is part of a pipeline? Start with a prediction before expanding the experiment.