A topic in the Open Knowledge Graph — a free, open map of 15,290 topics and the order to learn them in.

Shared Memory Inter-Process Communication

College Depth 98 in the knowledge graph ☐ I know this ☆ Set as goal
1topic build on this
368prerequisites beneath it
See this on the map →
Inter-Process Communication (IPC)Virtual Memory and Demand Paging→→Sockets and Network Inter-Process Communication
ipc shared-memory high-performance

Core Idea

Shared memory allows multiple processes to map the same memory region into their address spaces for high-speed data exchange without kernel overhead. Multiple processes can read and write simultaneously, requiring explicit synchronization to prevent data races and corruption. Shared memory is the fastest IPC mechanism but demands careful coordination and is vulnerable to one process corrupting another's data.

Explainer

From your study of IPC mechanisms, you know that processes are isolated by default — each has its own address space, and the kernel mediates all communication. Pipes and message queues work by copying data from one process into the kernel and then out to another. This double-copy is safe but expensive for large or frequent transfers. Shared memory eliminates the copies entirely by letting two or more processes map the same physical memory region into their respective virtual address spaces. Once the region is set up, reads and writes go directly to RAM with no kernel involvement, making it the fastest IPC mechanism available.

Setting up shared memory involves a few steps. One process creates a named shared memory segment (using system calls like `shmget` on Unix or `CreateFileMapping` on Windows), specifying its size. Other processes attach to that segment by name, receiving a pointer they can use like any other memory address. The operating system's virtual memory system — which you may have encountered as a prerequisite — handles the mapping so that the same physical frames back the virtual pages in each process. Once attached, processes read and write through ordinary pointer operations. When done, each process detaches, and the segment is destroyed when the last user releases it.

The speed advantage comes with a critical responsibility: synchronization is entirely your problem. Unlike pipes or message queues, where the kernel serializes access, shared memory provides no built-in ordering or mutual exclusion. If one process writes a data structure while another reads it, the reader may see a half-written, inconsistent state — a classic data race. You must layer your own synchronization on top, typically using semaphores, mutexes in shared memory, or other coordination primitives. A common pattern is a producer-consumer ring buffer in shared memory, where one process writes to the next available slot and another reads from the oldest unread slot, with semaphores tracking how many slots are full and empty.

Shared memory is most valuable when processes exchange large volumes of data at high frequency — video frames, audio buffers, database page caches, or scientific simulation grids. For small, infrequent messages, the complexity of manual synchronization usually outweighs the performance gain, and simpler IPC like pipes or sockets is preferable. The tradeoff is direct: maximum speed in exchange for maximum programmer responsibility. A bug in one process can corrupt the shared region and crash or silently corrupt every other process attached to it, so defensive programming — checksums, version fields, careful lock discipline — is essential in production shared-memory systems.

Practice Questions 5 questions

Prerequisite Chain

Understanding Zero → The Number Zero → Counting to Five → Counting to 10 → Counting to 20 → Counting a Set of Objects Up to 20 → Cardinality: The Last Number Counted → Matching Numerals to Quantities → Subitizing Small Quantities → Addition Within 10 → Number Bonds to 10 → Addition Within 20 → Doubles and Near Doubles → Doubles Facts Within 10 → Near Doubles Facts Within 20 → Mental Math Strategies for Addition → Mental Math: Adding and Subtracting Tens → Addition Within 100 → Repeated Addition as Multiplication → Multiplication as Equal Groups → Multiplication: Arrays → Basic Multiplication Facts (0s, 1s, 2s, 5s, 10s) → Multiplication Facts Within 100 → Division as Equal Sharing → Division as Grouping (Measurement Division) → Division: Grouping (Repeated Subtraction) Model → Division: Fair Sharing Model → Division as Equal Sharing → Division as Grouping → Basic Division Facts → Division Facts Within 100 → Multiplication and Division Fact Families → Relationship Between Multiplication and Division → Division Facts as Inverse of Multiplication → Remainders and Quotients in Division → Division Word Problems → Multi-Step Word Problems → Solving Multi-Step Word Problems → Multiplication Word Problems → Division Word Problems → Introduction to Long Division → Factors and Multiples → Prime and Composite Numbers → Equivalent Fractions → Relating Fractions and Decimals → Decimal Place Value → Integers and the Number Line → Comparing and Ordering Integers → Absolute Value → Adding Integers → Subtracting Integers → Multiplying Integers → Introduction to Exponents → Order of Operations → Integer Order of Operations → Variable Expressions → The Distributive Property → Variables and Expressions Review → Introduction to Polynomials → Adding and Subtracting Polynomials → Multiplying Polynomials → Factorial → Permutations → Combinations → Counting Principles: Addition and Multiplication Rules → Introduction to Graph Theory → Propositional Logic Foundations → Logical Equivalences → Boolean Algebra → Boolean Type and Truth Values → Comparison Operators and Boolean Tests → Logical Operators and Boolean Algebra → Boolean Algebra and Fundamental Laws → Logic Gates Fundamentals → Implementing Boolean Functions with Gates → Karnaugh Map Simplification → Combinational Circuit Design → Flip-Flops and Latches → Binary Counters: Design and Analysis → Binary Arithmetic → Fixed-Point Number Representation → Two's Complement Representation → Overflow and Underflow Detection → Binary Adders: Half-Adders and Full-Adders → Full Adder and Carry Propagation → Carry Lookahead Adder Design → Half Adder Circuit Design → Multiplication Circuit Design → Sequential Circuit Design → Registers and Register Files → Instruction Set Architecture (ISA) → Assembly Language Basics → Memory Organization and Addressing → Memory Hierarchy → Cache Memory Design → Cache Replacement Policies → Virtual Memory and Paging → Virtual Memory and Demand Paging → Shared Memory Inter-Process Communication

Longest path: 99 steps · 368 total prerequisite topics

Prerequisites (2)

Leads To (1)