Concept lesson

Linux Process Lifecycle & IPC

fork(), execve(), Unix domain sockets, named pipes, and shared memory allocation.

lesson
Freshness: current15 min read
Mastery
not started · 0%

Learning outcomes

  • Trace process creation and memory copy-on-write mechanics
  • Build fast inter-process communication using Unix domain sockets

Mental model

In Linux, every process (except init / systemd PID 1) is created when a parent process clones itself via fork(), duplicating page tables with Copy-On-Write (COW) optimization, before loading a new executable image via execve().

Parent Process invokes fork()
Kernel duplicates Task Struct & Page Tables (COW)
Child Process invokes execve('/bin/app')
Kernel replaces Process Address Space
Child exits -> Parent reaps via waitpid()
Conceptual teaching model synthesized from:Linux Kernel Kernel.org Official Architecture & Systems Documentation

Theory

  • Copy-On-Write (COW): fork() marks page table entries read-only for both parent and child. Physical memory pages are only duplicated when either process attempts to write to a page.
  • Inter-Process Communication (IPC):
    • Unix Domain Sockets (AF_UNIX): Fast local IPC bypassing network stack protocol overhead.
    • Shared Memory (shmget / mmap): Fastest IPC; processes map the same physical RAM pages into their virtual address spaces.
// C example: Process Forking & Executive Execution
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>

int main() {
    pid_t pid = fork();
    if (pid == 0) {
        // Child Process
        char *args[] = {"/bin/ls", "-l", NULL};
        execve(args[0], args, NULL);
    } else if (pid > 0) {
        // Parent Process waits for child exit to prevent zombie process
        int status;
        waitpid(pid, &status, 0);
        printf("Child process %d exited.\n", pid);
    }
    return 0;
}

Alternatives and trade-offs

  • Unix Domain Sockets: High speed, supports socket permissions and passing file descriptors (SCM_RIGHTS).
  • Shared Memory (mmap): Zero-copy performance; requires explicit locking mutexes (spinlocks / semaphores) to prevent memory corruption.

Failure modes and misconceptions

  1. Zombie Processes: If a parent process fails to invoke wait() / waitpid() after a child exits, the child process entry remains in the kernel process table as a Zombie (Z state), consuming PIDs.
  2. COW Memory Spikes: Forking a process with 10GB allocated RAM causes a sudden memory spike if the child process mutates large memory arrays, triggering page duplications.
Reflect before revealing the guide

Decision scenario

Use Unix Domain Sockets (AF_UNIX) for high-throughput local IPC between containerized sidecar processes to avoid TCP network stack overhead.

Learning outcomes

  • Trace Linux process creation using fork() and execve().
  • Explain Copy-On-Write (COW) memory page mapping during process cloning.
  • Prevent zombie processes by managing parent waitpid() signals.

Trade-offs

fork() enables rapid process creation via Copy-On-Write page tables, but un-reaped terminated children accumulate as zombie processes in the kernel task list.

Evidence assessment

Theory and decision mastery

not-started · 0%
theory0%
decision0%
activityNot mapped
projectNot mapped
1. What is the core architectural principle governing linux process lifecycle ipc?
2. What primary operational trade-off must be managed when configuring linux process lifecycle ipc?
3. Which failure mode is most commonly observed when linux process lifecycle ipc is misconfigured?

Decision scenario

You are designing a high-concurrency production system requiring reliable execution of linux process lifecycle ipc under heavy traffic load.

Which architectural decision ensures maximum resilience, scalability, and system stability?

Primary sources