02-process-vs-thread-and-ipc.md

๐Ÿงต OS 02: Process vs Thread & Inter-Process Communication (IPC)

Targeted for: Juspay Elimination Round, Hackathon Part B System Discussion & High-Concurrency Architecture
Key Focus: Memory isolation vs sharing, Kernel vs User threads, IPC deep dive (Pipes, Shared Memory, Message Queues, Sockets), and Thread Lifecycle.


โš–๏ธ 1. Process vs Thread: The Complete Comparison

PROCESS 1 (PID: 101) PROCESS 2 (PID: 102) โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ CODE SEGMENT (Instructions) โ”‚ โ”‚ CODE SEGMENT (Instructions) โ”‚ โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค โ”‚ DATA SEGMENT (Global Variables) โ”‚ โ”‚ DATA SEGMENT (Global Variables) โ”‚ โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค โ”‚ HEAP (malloc/new memory) โ”‚ โ”‚ HEAP (malloc/new memory) โ”‚ โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค โ”‚ FILE DESCRIPTORS (Open Files, Sockets) โ”‚ โ”‚ FILE DESCRIPTORS (Open Files, Sockets) โ”‚ โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค โ”‚ THREAD 1 THREAD 2 โ”‚ โ”‚ THREAD 1 โ”‚ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ โ”‚ โ”‚ Stack Frame โ”‚ โ”‚ Stack Frame โ”‚ โ”‚ โ”‚ โ”‚ Stack Frame โ”‚ โ”‚ โ”‚ โ”‚ CPU Regs (PC)โ”‚ โ”‚ CPU Regs (PC)โ”‚ โ”‚ โ”‚ โ”‚ CPU Regs (PC)โ”‚ โ”‚ โ”‚ โ”‚ Thread ID โ”‚ โ”‚ Thread ID โ”‚ โ”‚ โ”‚ โ”‚ Thread ID โ”‚ โ”‚ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ–ฒ โ–ฒ โ”‚ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ IPC (Shared Memory, Sockets) โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Comprehensive Comparison Matrix

DimensionProcessThread (Lightweight Process)
DefinitionAn independent executing program instance with isolated resource ownership.The basic unit of CPU execution within a process context.
Address SpaceIsolated: Separate virtual address spaces. Process A cannot read/write Process B's memory directly.Shared: All threads within a process share the exact same Text, Data, Heap, and File Descriptors.
Private StatePCB, Full Virtual Memory, File Table, Signal Table, Stack, Registers.Stack, Registers / Program Counter (PC), Thread Local Storage (TLS), TID, Signal Mask.
Creation CostHeavyweight: Requires cloning page tables, duplicating file descriptors, allocating new PCB (fork(), ~0.5โ€“2 ms).Lightweight: Allocates a small stack (~2โ€“8 MB) and a minimal kernel structure (pthread_create(), ~10โ€“50 ยตs).
Context Switch OverheadHigh: Must save registers, switch Page Table Base (reload CR3 register), and flush TLB (Translation Lookaside Buffer).Low: Only saves/restores CPU registers and stack pointer. No MMU page table reload; TLB remains valid.
Fault IsolationComplete: If Process A crashes (Segmentation fault / SIGSEGV), Process B is completely unaffected.Zero: If Thread A dereferences a NULL pointer or corrupts heap memory, the entire process and all threads crash.
CommunicationExpensive: Must use IPC (Pipes, Shared Memory, Sockets) requiring kernel system calls.Ultra-fast: Direct reads/writes to shared variables on the Heap or Global Data (requires synchronization locks).
Synchronization NeedLower: Independent memory means implicit safety, unless explicitly sharing memory.Critical: High contention on shared state demands Mutex, Semaphores, Atomic instructions, or CAS.

๐Ÿ”„ 2. Thread Lifecycle States

Threads follow a refined state transition model closely aligned with OS and runtime execution (e.g., POSIX pthreads, Java/JVM Thread States):

stateDiagram-v2 [*] --> NEW : Thread Object Instantiated NEW --> RUNNABLE : start() / pthread_create() RUNNABLE --> RUNNING : CPU Scheduler assigns time slice RUNNING --> RUNNABLE : yield() / Time quantum expires RUNNING --> BLOCKED : Waiting for Lock / Mutex RUNNING --> WAITING : wait() / join() / LockSupport.park() RUNNING --> TIMED_WAITING : sleep(ms) / wait(timeout) BLOCKED --> RUNNABLE : Lock acquired WAITING --> RUNNABLE : notify() / notifyAll() / unpark() TIMED_WAITING --> RUNNABLE : Timeout expired / notify() RUNNING --> TERMINATED : run() finishes / Exception thrown TERMINATED --> [*]

Thread States Explained

  1. NEW: The thread object has been created in memory, but start() / pthread_create() has not yet been called. The kernel thread has not spawned.
  2. RUNNABLE / READY: The thread is eligible to run and sits in the OS Ready Queue awaiting CPU time.
  3. RUNNING: The thread is actively executing instructions on a physical CPU core.
  4. BLOCKED: The thread is suspended waiting to acquire an exclusive lock (e.g., waiting outside a synchronized block or pthread_mutex_lock).
  5. WAITING: The thread has explicitly paused its own execution indefinitely (e.g., calling wait(), pthread_cond_wait(), or thread.join()). It will not wake up until another thread sends a notification (notify() / pthread_cond_signal()).
  6. TIMED_WAITING: The thread is paused for a specified duration (e.g., sleep(1000), poll(timeout)).
  7. TERMINATED (DEAD): The thread has completed its execution or was terminated due to an uncaught exception. Its stack is deallocated.

๐Ÿงต 3. Threading Models: User-Level vs Kernel-Level

Many-to-One (N:1) One-to-One (1:1) Many-to-Many (M:N) (User Threads) (Standard Linux/Windows) (Go Goroutines / Erlang) [U1] [U2] [U3] [U1] [U2] [U3] [U1] [U2] [U3] [U4] \ | / | | | \ \ / / [User Library] | | | [Go Runtime M:N] | | | | / | \ [ K1 ] [ K1 ] [ K2 ] [ K3 ] [ K1 ][ K2 ][ K3 ]
  1. Many-to-One (N:1 - Green Threads):
    • User space library schedules threads without kernel awareness.
    • Advantage: Ultra-fast context switching (no kernel transitions).
    • Fatal Flaw: If one thread makes a blocking I/O call, the OS blocks the entire process (all user threads freeze). Cannot utilize multicore CPUs in parallel.
  2. One-to-One (1:1 - POSIX pthreads, Java threads, C++ std::thread):
    • Every user thread maps directly to an OS kernel thread (task_struct).
    • Advantage: True multicore hardware parallelism. A blocking thread does not block siblings.
    • Disadvantage: Higher memory footprint (~2MB stack per thread) and context switch requires a kernel mode switch.
  3. Many-to-Many (M:N - Hybrid / Go Goroutines / Kotlin Coroutines):
    • Multiplexes $M$ lightweight user tasks over $N$ kernel worker threads.
    • Goroutines start with a tiny 2KB dynamic stack, allowing millions of concurrent tasks with microsecond scheduling.

๐Ÿ“ก 4. Inter-Process Communication (IPC) Deep Dive

When processes must cooperate, they cannot simply read each other's memory. The OS provides 6 distinct IPC Mechanisms:

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ IPC MECHANISM TAXONOMY โ”‚ โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค โ”‚ Mechanism โ”‚ Throughput / Speed โ”‚ Communication Scope โ”‚ โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค โ”‚ 1. Anonymous Pipes โ”‚ Moderate (Kernel buffer) โ”‚ Parent-Child processes on 1 host โ”‚ โ”‚ 2. Named Pipes (FIFO) โ”‚ Moderate (Kernel buffer) โ”‚ Unrelated processes on 1 host โ”‚ โ”‚ 3. Message Queues โ”‚ Moderate (Kernel queue) โ”‚ Unrelated processes on 1 host โ”‚ โ”‚ 4. Shared Memory โ”‚ ๐Ÿ”ฅ FASTEST (Zero-Copy) โ”‚ Unrelated processes on 1 host โ”‚ โ”‚ 5. Unix Domain Sockets โ”‚ Very High (Bypasses IP) โ”‚ Unrelated processes on 1 host โ”‚ โ”‚ 6. Network Sockets โ”‚ High / Latency-bound โ”‚ Across Different Machines / LAN โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Detailed Breakdown of Each Mechanism

1. Pipes (Anonymous & Named)

  • Anonymous Pipes (pipe() system call):
    • Unidirectional (Half-duplex) byte stream between parent and child processes created before fork().
    • Managed inside a circular kernel buffer (typically 64 KB).
    • Example in shell: cat transactions.log | grep "FAILED" | wc -l.
  • Named Pipes / FIFOs (mkfifo() system call):
    • Appears as a special FIFO file on the filesystem (e.g., /tmp/payment_pipe).
    • Allows communication between completely unrelated processes running under different user accounts.

2. Message Queues (POSIX mq_open / mq_send / mq_receive)

  • Stores structured messages in a kernel-managed linked list.
  • Unlike byte-stream pipes, message queues preserve message boundaries and support message priorities (higher-priority messages are dequeued before older, lower-priority ones).

3. Shared Memory (shmget / shmat or POSIX shm_open + mmap) โ€” ๐Ÿ”ฅ The Gold Standard for Speed

  • The OS maps the exact same physical RAM frames into the virtual address spaces of two or more independent processes.
  • Zero-Copy Architecture: Data written by Process A is immediately visible to Process B at memory bus speed without copying bytes through kernel space.
  • The Catch: The OS provides no synchronization. Processes must coordinate concurrent reads/writes using POSIX named semaphores (sem_open) or process-shared mutexes (PTHREAD_PROCESS_SHARED).
Virtual Address Space A Physical RAM Frame Virtual Address Space B โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ Page Table A โ”‚ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€>โ”‚ Shared Physical โ”‚<โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ โ”‚ Page Table B โ”‚ โ”‚ Virtual: 0x70000000 โ”‚ โ”‚ Memory Frame โ”‚ โ”‚ Virtual: 0x50000000 โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

4. Sockets (Unix Domain Sockets vs TCP/IP Sockets)

  • Unix Domain Sockets (AF_UNIX / AF_LOCAL):
    • Optimized local IPC. Uses standard socket API (socket(), bind(), connect()), but data transfers occur entirely in-memory inside the kernel without packetizing, checksumming, or TCP/IP routing overhead.
    • Standard for local database connections (e.g., PostgreSQL /var/run/postgresql/.s.PGSQL.5432 or Redis /var/run/redis/redis.sock).
  • Network Sockets (AF_INET - TCP/UDP):
    • Enables communication across physical network boundaries. Heavyweight protocol overhead, but universal.

5. Signals (kill() system call)

  • Asynchronous notifications sent from the kernel or another process (e.g., SIGINT (Ctrl+C), SIGTERM (graceful shutdown), SIGKILL (immediate uncatchable termination), SIGCHLD (child state change)).
  • Cannot carry complex data payloads (limited to signal number and optional siginfo_t).

๐ŸŽฏ 5. When to Use Which: Architectural Decision Framework

Do processes run on different physical machines? / \ YES NO / \ [ Network Sockets ] Do you need maximum possible throughput (TCP / gRPC) with multi-gigabyte data sets? / \ YES NO / \ [ Shared Memory ] Do you need structured messages + Named Semaphore with priority handling? / \ YES NO / \ [ Message Queue ] Is it streaming data / parent-child? / \ YES NO / \ [ Unix Pipe ] [ Unix Domain Socket ]

Real-World Production Examples

  1. Google Chrome Architecture (Multi-Process):
    • Each browser tab runs in an isolated process. If an untrusted JavaScript script crashes or infinite loops in Tab 1, Tabs 2, 3, and 4 continue running smoothly. Tab processes communicate with the main Browser process via Named Pipes / Mojo IPC.
  2. Nginx Web Server (Multi-Process + Shared Memory):
    • Nginx runs 1 Master process and $N$ Worker processes (one per CPU core). Worker processes share connection limits, cache metadata, and rate-limiting counters via Shared Memory zones (shm) with spinlocks.
  3. High-Throughput Payment Engine (Juspay Context):
    • High-throughput processing threads within the same process share the M-ary tree state directly on the Heap. Cross-service transaction logging delegates to Redis / Kafka via TCP Sockets or local Unix Sockets.

๐Ÿ’ฌ 6. Verbatim Interview Scripts (Say This Out Loud)

Q: "When would you choose multiple processes over multiple threads for a system?"

Verbatim Answer:
"I choose multiple processes when fault isolation, security sandboxing, or privilege separation is paramount. In a multi-process architecture (like Google Chrome tabs or Nginx worker processes), if one worker suffers a memory corruption or segfault, other workers and the main daemon remain fully operational. Furthermore, processes can run under distinct OS user privileges and security policies.

Conversely, I choose multiple threads when ultra-low latency, high shared-state throughput, and frequent context switches are required. Threads share the same address space, avoiding IPC serialization costs and heavy kernel context switches. However, threads require rigorous concurrency synchronization since a single unhandled exception will crash the entire process."

Q: "What is the fastest IPC mechanism available on Linux, and what is its primary drawback?"

Verbatim Answer:
"The fastest IPC mechanism is Shared Memory (shm_open + mmap or shmget). It maps the same physical memory frames into the virtual address spaces of communicating processes. Once mapped, reads and writes occur directly at hardware memory bus speeds with zero kernel context switches and zero intermediate buffer copying.

Its primary drawback is that the OS provides no built-in synchronization. Unlike pipes or message queues, shared memory does not block a reader when data is not ready, nor does it prevent race conditions. Developers must explicitly implement synchronization using POSIX named semaphores, process-shared mutexes, or atomic CAS operations."