Process Termination
100%

Processes · Lesson 5

Process Termination

Learn how exit status, waiting, zombies, and reparenting complete the Linux process lifecycle.

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.

By Unix convention, which normal exit status indicates success?

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.

What does a successful wait operation let a parent retrieve?

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.

Which description matches a zombie process?

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.

What happens when a process outlives its original parent?

Lesson complete

You finished Process Termination

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.

Keep your learning progress

Create a free account to save this lesson and continue learning on any device.

Create a free account
Next Lesson
Back to Processes