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().
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.
- Unix Domain Sockets (
// 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
- 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 (Zstate), consuming PIDs. - 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.
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()andexecve(). - 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
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
- Linux Kernel Kernel.org Official Architecture & Systems Documentation — Linux Kernel Organization, verified 2026-07-23