Process Creation and Termination

How a New Process Comes Into Existence

A new process is almost always created by an existing process (the "parent") requesting one - a genuinely new process rarely appears out of nowhere; it's typically spawned by something already running.

A Common Pattern: fork() Then exec()

Parent process
     |
   fork()  ---->  creates a near-identical copy (the child process)
     |
   child calls exec()  ---->  replaces the child's own code with a completely new program

In many operating systems, creating a process for a genuinely different program happens in two distinct steps: fork() creates a near-exact duplicate of the calling process, and exec() then replaces that duplicate's code entirely with a different program - together producing a brand-new process running different code.

The Parent-Child Relationship

A newly created process typically becomes a "child" of the process that created it, forming a tree-like hierarchy of processes - most operating systems track this relationship, since it affects things like resource inheritance and cleanup responsibilities.

How a Process Terminates

A process terminates either normally (it finishes its work and exits on its own) or abnormally (it's forcibly killed, due to an unrecoverable error or an explicit request from another process). Either way, the OS reclaims all resources the process was using - memory, open files, and its PCB entry.

A Notable Edge Case: Zombie Processes

When a child process terminates, its exit status is kept around briefly so the parent process can retrieve it. If the parent never actually retrieves that status, the terminated child can linger in a "zombie" state - technically finished, but not yet fully cleaned up, since the OS is still holding onto that small amount of exit information for the parent.

Why Understanding Creation and Termination Matters

Correctly creating and cleaning up processes is foundational to writing reliable software - a program that creates processes without properly handling their termination can leak system resources over time, a subtle but genuinely real class of bug.

Written by Lorens Mishra

Software Engineer Notes Management System Administrator

Discussion

0 comments
Sign in to join the discussion.

No comments yet. Be the first to say something.