Processes · Lesson 5 of 11
Process Termination
0 / 4 checkpoints answered
A process can finish by returning from its main function, calling an exit interface, or being terminated by a signal. The kernel releases most of its resources, but parent-child accounting continues until the parent collects the termination information.
Exit Status
A normally exiting program supplies an integer status. By convention, status 0 means success and a nonzero value reports some form of failure or alternate outcome. The exact meanings of nonzero values belong to the program's interface.
In a shell, inspect the most recent foreground pipeline's status with:
$ command
$ printf '%s\n' "$?"
Shells expose a limited encoded status range and also represent signal termination, so this value is not a complete diagnostic record. Programs should document their own exit codes.
CheckBy Unix convention, which normal exit status indicates success?
press 1/2/3 to answer · → next lesson
Waiting and Reaping
The kernel records how a child terminated and notifies its parent. The parent uses a member of the wait() system-call family to retrieve that information. Collecting the record is called reaping.
Waiting can also coordinate execution: a shell waits for a foreground command before displaying another prompt, while it can defer waiting for a background job. A well-designed long-running parent must arrange to reap children without blocking unrelated work.
CheckWhat does a successful wait operation let a parent retrieve?
press 1/2/3 to answer · → next lesson
Zombie Processes
After a child exits but before its termination record is reaped, it appears as a zombie, often with state Z in ps. It no longer executes and retains no ordinary address space, but a minimal process-table entry and accounting information remain.
Sending a signal to a zombie cannot make it exit again. Fix persistent zombie accumulation by diagnosing the parent that is failing to wait, restarting or correcting that parent through an appropriate operational procedure, or allowing reparenting to a process that will reap it. Large numbers can exhaust PID or process-table capacity.
CheckWhich description matches a zombie process?
press 1/2/3 to answer · → next lesson
Orphans and Reparenting
If a parent exits while its child remains, the kernel reparents that child to an eligible subreaper or to the init process in the relevant PID namespace. The child may be running, sleeping, stopped, or later become a zombie; “orphan” describes the lost original parent relationship rather than one execution state.
The adopting process becomes responsible for collecting termination status. Modern service managers and container environments make it important not to assume that the new parent is always the host's PID 1.
CheckWhat happens when a process outlives its original parent?
press 1/2/3 to answer · → next lesson
Use the Manage and Monitor Linux Processes lab to observe exit codes and process states without disrupting a production workload.
Summary
You can now distinguish execution ending from parent-side cleanup.
- Interpret zero as conventional success and nonzero statuses by program documentation.
- Use waiting to collect a child's termination information.
- Recognize a zombie as exited but unreaped.
- Recognize an orphan as a child reparented after its original parent exits.
Lesson complete
You finished Process Termination. Nice work — keep the momentum going.