Processes & the Process Abstraction

process termination

When a guest checks out of a hotel, they hand back the key, the room is cleared, and a final bill is left at the desk for the front office to settle. A process ending is much the same: it stops running, the OS reclaims its resources, and it leaves behind a small result for its parent to pick up. Process termination is how a process finishes and is wound down, with an exit status reporting how it went.

A process usually terminates by calling exit (or by returning from its main function, which the runtime turns into an exit), passing a small integer, the exit status or return code, that conventionally means 0 for success and non-zero for some kind of failure. A process can also be terminated involuntarily, by a signal (for example after a fatal error or because someone killed it). On termination the OS reclaims most resources, closing the process's files and freeing its memory, but one thing must persist briefly: the exit status, kept so the parent can read it. The process is now terminated but not yet gone; it remains a zombie until the parent reaps it with wait.

Termination matters because the exit status is how programs report success or failure to whoever started them, letting scripts and shells make decisions ('did the command succeed?'). The subtle part is the handshake at the end: termination is not truly complete until the parent collects the status. If the parent never does, the entry lingers as a zombie; if the parent has already died, init takes over and reaps it. So 'the process ended' really has two stages, it stops and reports, then it is reaped and removed.

A program finishes its work and calls exit(0), meaning success. Its parent later runs wait, reads the status 0, and knows the program succeeded. Had it failed, it might have called exit(1) instead.

Exit status 0 means success; non-zero conventionally means failure.

A terminated process is not fully gone until its parent reaps it. Until then it remains a zombie holding its exit status and a process-table entry.

Also called
process exitexit statusreturn code行程終止退出狀態