100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
C

Interprocess Communication

How independent processes with separate address spaces exchange data and coordinate using OS-provided IPC mechanisms.

Concurrency & IPCIntermediate9 min readJul 8, 2026
Analogies

Introduction

Every process runs in its own private virtual address space, isolated from other processes for protection and stability. This isolation is a feature, not a bug, but it also means processes cannot simply read each other's memory or call each other's functions directly. Interprocess Communication (IPC) is the collective name for the OS-supported mechanisms that let separate processes exchange data and synchronize their actions despite this isolation. Without IPC, cooperating multi-process applications (shells with pipelines, client-server systems, database engines with worker processes) would be impossible to build safely.

🏏

Cricket analogy: Two rival dressing rooms are strictly off-limits to each other's players during a match, so any coordination between teams (like agreeing on a rain-delay resumption time) must go through the match referee acting as an intermediary, not by players walking into the other room.

Syntax

c
#include <unistd.h>
#include <sys/wait.h>
#include <stdio.h>

int main(void) {
    int fd[2];
    if (pipe(fd) == -1) {          /* fd[0]=read end, fd[1]=write end */
        perror("pipe");
        return 1;
    }

    pid_t pid = fork();
    if (pid == 0) {
        /* child: writer */
        close(fd[0]);
        write(fd[1], "hello", 5);
        close(fd[1]);
        _exit(0);
    } else {
        /* parent: reader */
        close(fd[1]);
        char buf[16];
        ssize_t n = read(fd[0], buf, sizeof(buf));
        write(STDOUT_FILENO, buf, n);
        close(fd[0]);
        wait(NULL);
    }
    return 0;
}

Explanation

IPC mechanisms broadly fall into two models. The first is shared memory, where the kernel maps the same physical memory region into the virtual address spaces of two or more processes; once mapped, processes read and write that region directly using ordinary memory instructions, with no kernel involvement per access, making it extremely fast but requiring the processes to synchronize access themselves. The second is message passing, where processes exchange data by sending and receiving discrete messages through the kernel (pipes, message queues, sockets); every transfer goes through a system call, which is slower but the kernel naturally serializes operations and no shared address space is needed. POSIX and System V both provide standardized IPC facilities implementing these models: pipes, FIFOs, message queues, shared memory segments, semaphores, and sockets.

🏏

Cricket analogy: A shared electronic scoreboard both teams' analysts can read and write to directly, with no official mediating each update, is fast but requires both sides to agree on update etiquette to avoid overwriting each other's entries -- versus radio-relayed updates through the match referee, slower but naturally ordered and conflict-free.

Example

c
/* Same pipe example above demonstrates message-passing IPC:
   the kernel buffer inside the pipe is the communication channel,
   and read()/write() are the message-passing primitives. */
#include <unistd.h>
#include <stdio.h>

void demo(void) {
    int fd[2];
    pipe(fd);
    /* fd[1] write end feeds data into a kernel-managed buffer;
       fd[0] read end drains it -- no shared memory involved */
    printf("pipe created: read fd=%d write fd=%d\n", fd[0], fd[1]);
}

Analysis

In the pipe example, the parent and child never touch each other's memory; the kernel owns an internal buffer and copies bytes in on write() and out on read(). This is why message passing works cleanly even between unrelated processes (via named pipes, message queues, or sockets) while remaining safe: the kernel enforces ordering and atomicity of each call. Choosing between the two models is a classic tradeoff of raw performance (shared memory) versus safety and simplicity (message passing) that recurs throughout OS design.

🏏

Cricket analogy: In a father-son coaching drill, the father never touches the son's bat directly; a coach standing between them relays feedback -- "adjust your grip" -- one instruction at a time, which is why the method works safely even between players who've never met, since the coach enforces order.

Key Takeaways

  • Processes have separate address spaces by default; IPC is the OS-provided bridge between them.
  • The two general IPC models are shared memory (direct, fast, needs manual synchronization) and message passing (kernel-mediated, slower, self-synchronizing).
  • Common IPC facilities: pipes, FIFOs, message queues, shared memory segments, semaphores, sockets.
  • Message passing goes through system calls every time; shared memory only incurs kernel cost at setup.

Practice what you learned

Was this page helpful?

Topics covered

#OperatingSystemsStudyNotes#OperatingSystems#InterprocessCommunication#Interprocess#Communication#Syntax#Explanation#StudyNotes#SkillVeris#ExamPrep