How Linux Distinguishes Parent and Child Processes

In the Linux operating system, processes exist in a strict hierarchical tree where every process (except the initial systemd or init process) is spawned by a parent. Linux differentiates between a parent and a child process primarily through the return value of the fork() system call, distinct Process Identifiers (PIDs and PPIDs), and internal tracking within the kernel’s process control block. This article breaks down the exact mechanisms the kernel and user space use to tell parent and child processes apart.

1. The fork() System Call Return Value

The primary programmatic distinction occurs at the exact moment of creation. When an existing process calls the fork() system call, the kernel creates an almost identical duplicate of the calling process.

Both processes continue execution at the instruction immediately following the fork() call, but the operating system delivers different return values to each:

Programmers use a simple conditional block (if/else) evaluating this return value to define different behaviors for the parent and the child.

2. PID and PPID (Process Identifiers)

At the user and administrative levels, Linux distinguishes between processes using numerical identifiers:

You can observe this directly in user space using commands such as ps -ef or pstree, or by checking the /proc filesystem (e.g., inspecting the PPid field in /proc/[PID]/status). Inside C code, a process can find its own identity using getpid() and its parent's identity using getppid().

3. Kernel Tracking via task_struct

Internally, the Linux kernel represents every process as an instance of the struct task_struct structure (the process control block). The kernel maintains the parent-child relationship using dedicated pointer fields within this structure:

These pointers enable the kernel to manage lifecycle events, such as passing exit status codes when a child terminates (via wait() or waitpid()) or re-parenting orphaned children to init (PID 1) if the parent process dies before the child.

4. Resource Allocation and Copy-on-Write (COW)

While a child process inherits file descriptors, environment variables, and memory mappings from its parent, the kernel isolates their execution using virtual memory management.

Linux employs a technique called Copy-on-Write (COW):

This ensures that while the child starts as a duplicate, the operating system maintains complete memory separation, allowing both processes to run independently without corrupting each other's state.