Skip to main content
Be Bitwise

IPC Mechanisms Compared

System Calls Across Operating Systems · Operating Systems track

13 min read

In this module

How Processes Talk to Each Other

Inter-Process Communication is how separate processes pass data, coordinate, and gossip about each other. Every OS ships a grab-bag of IPC mechanisms, each tuned for a different shape of problem. Some are universal (pipes, sockets, shared memory). Others are weird platform-specific creatures. Get the lay of the land here and a lot of "how does this actually work" mysteries on modern desktops dissolve.

Universal IPC: Pipes

Pipes are the simplest IPC primitive going, and you'll find them on every serious OS.

Anonymous Pipes

An anonymous pipe is a one-way pipe between two related processes — almost always parent and child:

c
// Linux
int pipefd[2]; // pipefd[0] = read end, pipefd[1] = write end
pipe(pipefd);
pid_t pid = fork();
if (pid == 0) {
// Child: close write end, read from pipe
close(pipefd[1]);
char buf[256];
read(pipefd[0], buf, sizeof(buf));
close(pipefd[0]);
} else {
// Parent: close read end, write to pipe
close(pipefd[0]);
write(pipefd[1], "Hello child!", 12);
close(pipefd[1]);
}
c
// Windows
HANDLE hReadPipe, hWritePipe;
SECURITY_ATTRIBUTES sa = { sizeof(sa), NULL, TRUE }; // Inheritable
CreatePipe(&hReadPipe, &hWritePipe, &sa, 0);
// Pass one end to child via CreateProcess + handle inheritance
// Parent writes to hWritePipe, child reads from hReadPipe

The kernel buffers pipe data — 64 KB on Linux, 4 KB by default on Windows. Fill the buffer and write() goes to sleep until the reader chews through some of it.

Named Pipes

Named pipes get a name — sitting in the filesystem on Linux, in a dedicated namespace on Windows — so unrelated processes can find them.

c
// Linux: named pipe (FIFO)
mkfifo("/tmp/myfifo", 0666);
// Writer process:
int fd = open("/tmp/myfifo", O_WRONLY);
write(fd, "data", 4);
// Reader process:
int fd = open("/tmp/myfifo", O_RDONLY);
read(fd, buf, sizeof(buf));

Windows named pipes do a lot more heavy lifting. They go both ways, can preserve message boundaries, and route over the network:

c
// Windows server: create named pipe
HANDLE hPipe = CreateNamedPipe(
"\\\\.\\pipe\\MyPipe", // Pipe name
PIPE_ACCESS_DUPLEX, // Bidirectional
PIPE_TYPE_MESSAGE | // Message mode
PIPE_READMODE_MESSAGE |
PIPE_WAIT,
PIPE_UNLIMITED_INSTANCES, // Max instances
512, 512, // Buffer sizes
0, // Default timeout
NULL // Security attributes
);
ConnectNamedPipe(hPipe, NULL); // Wait for client
// Windows client: connect to named pipe
HANDLE hPipe = CreateFile(
"\\\\.\\pipe\\MyPipe", // Can be \\server\pipe\MyPipe for remote!
GENERIC_READ | GENERIC_WRITE,
0, NULL, OPEN_EXISTING, 0, NULL
);
Windows Named Pipes

Windows named pipes are far more capable than Linux FIFOs. They support bidirectional communication, message framing (preserving message boundaries), multiple simultaneous clients, and transparent network access. A client can connect to a pipe on a remote server using the UNC path \\server\pipe\PipeName. Many Windows services use named pipes for local IPC, including Windows RPC and parts of the SMB protocol.

Shared Memory

Shared memory wins the throughput race. Nothing gets copied — both processes map the same physical pages into their own virtual address spaces and read/write directly.

Linux: POSIX Shared Memory

c
// Process A: create and write
int fd = shm_open("/my_shm", O_CREAT | O_RDWR, 0666);
ftruncate(fd, 4096);
void *ptr = mmap(NULL, 4096, PROT_READ | PROT_WRITE,
MAP_SHARED, fd, 0);
strcpy(ptr, "Shared data from process A");
// Process B: open and read
int fd = shm_open("/my_shm", O_RDONLY, 0);
void *ptr = mmap(NULL, 4096, PROT_READ, MAP_SHARED, fd, 0);
printf("Received: %s\n", (char *)ptr);

Windows: Named Section Objects

c
// Process A: create file mapping (section object)
HANDLE hMapping = CreateFileMapping(
INVALID_HANDLE_VALUE, // Page file backed
NULL,
PAGE_READWRITE,
0, 4096, // Size
"Local\\MySharedMem" // Name
);
void *ptr = MapViewOfFile(hMapping, FILE_MAP_ALL_ACCESS,
0, 0, 4096);
strcpy(ptr, "Shared data from process A");
// Process B: open existing mapping
HANDLE hMapping = OpenFileMapping(
FILE_MAP_READ,
FALSE,
"Local\\MySharedMem"
);
void *ptr = MapViewOfFile(hMapping, FILE_MAP_READ, 0, 0, 4096);
printf("Received: %s\n", (char *)ptr);

Both flavours come with the usual catch: you have to synchronise yourself. Mutex, semaphore, futex — pick your poison. Without it, concurrent readers and writers will corrupt each other's data.

Sockets

Sockets are the universal hammer. Every platform has them, and they work locally as well as across networks.

Unix Domain Sockets (Linux/macOS)

Unix domain sockets give you the socket API for local IPC, skipping the entire TCP/IP machinery underneath:

c
// Server
int server_fd = socket(AF_UNIX, SOCK_STREAM, 0);
struct sockaddr_un addr = { .sun_family = AF_UNIX };
strcpy(addr.sun_path, "/tmp/my_socket");
bind(server_fd, (struct sockaddr *)&addr, sizeof(addr));
listen(server_fd, 5);
int client_fd = accept(server_fd, NULL, NULL);
// Client
int sock = socket(AF_UNIX, SOCK_STREAM, 0);
connect(sock, (struct sockaddr *)&addr, sizeof(addr));

They've got two tricks TCP sockets simply can't do. SCM_RIGHTS ferries an actual file descriptor across the boundary, and SCM_CREDENTIALS lets the receiver see the sender's PID, UID, and GID — handy for trustworthy local authentication.

Linux-Specific IPC

D-Bus

D-Bus is the message bus glueing together most of the modern Linux desktop and a chunk of system-level plumbing too:

text
┌──────────────┐ ┌──────────────┐
│ Application │ │ Application │
│ Client │ │ Client │
└──────┬───────┘ └──────┬───────┘
│ │
▼ ▼
┌─────────────────────────────────┐
│ D-Bus Daemon │
│ (dbus-daemon / dbus-broker) │
│ System Bus: org.freedesktop.* │
│ Session Bus: per-user │
└─────────────────────────────────┘
│ │
▼ ▼
┌──────────────┐ ┌──────────────┐
│NetworkManager│ │ systemd │
│ │ │ │
└──────────────┘ └──────────────┘

D-Bus provides:

  • Type-safe interfaces: Methods have defined signatures (e.g., (ss) = two strings)
  • Signal broadcasting: One-to-many notifications
  • Service activation: Services started on demand when first accessed
  • Access control: Policy files control who can call which methods

Netlink is a Linux-only socket family that talks straight to the kernel:

c
// Create a netlink socket for routing information
int sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
// Subscribe to network interface events
struct sockaddr_nl addr = {
.nl_family = AF_NETLINK,
.nl_groups = RTMGRP_LINK | RTMGRP_IPV4_IFADDR
};
bind(sock, (struct sockaddr *)&addr, sizeof(addr));
// Now recv() will deliver notifications when interfaces change

If you've ever run ip link, you've used netlink — it's the back-channel ip, iproute2, and NetworkManager use to wire up the kernel. Plenty of other subsystems (audit, SELinux, the connector) lean on it too for pushing events out to user space.

Windows-Specific IPC

Mailslots

Mailslots are Windows's one-way, fire-and-forget datagram channel. No delivery guarantees, no reply path:

c
// Server: create mailslot
HANDLE hSlot = CreateMailslot(
"\\\\.\\mailslot\\MyMailslot",
0, // Max message size (0 = any)
MAILSLOT_WAIT_FOREVER,
NULL
);
// Client: send message (can broadcast to domain)
HANDLE hFile = CreateFile(
"\\\\.\\mailslot\\MyMailslot", // or \\*\mailslot\... for broadcast
GENERIC_WRITE, FILE_SHARE_READ,
NULL, OPEN_EXISTING, 0, NULL
);
WriteFile(hFile, "Alert!", 6, &written, NULL);

Mailslots are legacy. Remote mailslots travel over SMBv1, which modern Windows disables, and Microsoft has deprecated them; local ones still work but nothing new should use them.

ALPC

ALPC (Advanced Local Procedure Call) is the kernel's fast message-passing transport between processes on the same machine, and it's the workhorse underneath much of Windows. Local RPC runs over it, so COM calls to out-of-process servers, the Service Control Manager, LSASS and countless system services all talk this way. Programs don't call the undocumented NtAlpc* functions directly; they get ALPC through RPC and COM. Because so many privileged services listen on ALPC ports, those ports are a well-trodden attack surface for local privilege escalation.

COM / DCOM

COM (the Component Object Model) is Windows's main component architecture. Cross-process method calls flow over IPC under the hood:

c
// Initialize COM
CoInitializeEx(NULL, COINIT_MULTITHREADED);
// Ask for an object that lives in another process. ShellWindows is
// served by explorer.exe, so CLSCTX_LOCAL_SERVER means out-of-process.
IShellWindows *psw;
HRESULT hr = CoCreateInstance(
&CLSID_ShellWindows, // Class ID
NULL, // No aggregation
CLSCTX_LOCAL_SERVER, // Out-of-process server (LocalServer32)
&IID_IShellWindows, // Interface ID
(void **)&psw // Output: a proxy in our process
);
// Each call is marshalled to explorer.exe over RPC (ALPC underneath)
long count;
psw->lpVtbl->get_Count(psw, &count);
// Release
psw->lpVtbl->Release(psw);
CoUninitialize();

DCOM stretches the same model across the network, so a method call can reach an object living on another machine without your code knowing the difference.

Key Concept
COM Threading Models

COM objects declare their threading model (single-threaded apartment, multi-threaded apartment, or both). The COM runtime uses IPC mechanisms (including Windows messages and RPC) to marshal method calls between apartments, ensuring thread safety. This is why COM initialisation (CoInitialize/CoInitializeEx) must specify the threading model.

macOS-Specific IPC

Mach Ports

Mach ports sit at the bottom of macOS's XNU kernel as the fundamental IPC primitive:

c
// Get our task's port
mach_port_t task = mach_task_self();
// Allocate a new receive right
mach_port_t port;
mach_port_allocate(task, MACH_PORT_RIGHT_RECEIVE, &port);
// Send a message
mach_msg_header_t msg;
msg.msgh_bits = MACH_MSGH_BITS(MACH_MSG_TYPE_COPY_SEND, 0);
msg.msgh_size = sizeof(msg);
msg.msgh_remote_port = destination_port;
msg.msgh_local_port = MACH_PORT_NULL;
mach_msg(&msg, MACH_SEND_MSG, sizeof(msg), 0,
MACH_PORT_NULL, MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL);

Internally, macOS leans heavily on Mach ports for the bones of its system services. launchd plays the role of bootstrap server, handing out port names and resolving lookups.

XPC

XPC is Apple's modern high-level IPC framework, built on top of Mach ports:

text
// XPC provides structured, sandboxed IPC
// Services are defined in an app's XPC service bundle
// Communication uses xpc_connection_t objects
// Messages are serialized dictionaries (xpc_object_t)

Security drives the whole design. Every XPC service lives in its own sandbox at minimum privilege, and launchd and the service itself decide who may connect, usually by checking the caller's code signature and entitlements.

IPC as a Trust Boundary

Every IPC endpoint is a door between two processes that may run with very different privileges. So the server's first job is working out who's knocking. Linux gives a Unix socket server SO_PEERCRED (the peer's PID, UID and GID at connect time), and D-Bus services typically hand the "is this caller allowed?" question to polkit. An XPC service on macOS should check the caller's audit token and entitlements before doing anything for it.

Windows named pipes add a twist that runs the other way. A pipe server can call ImpersonateNamedPipeClient() and take on the client's identity. That's the whole basis of the "potato" family of privilege escalations:

Named-pipe impersonation: the 'potato' pattern

PrintSpoofer, for instance, coaxes the print spooler into connecting to a pipe the attacker controls. The bug class is a confused deputy: a privileged process gets talked into using its authority on someone else's behalf. The same shape appears on every OS whenever a server trusts what it's asked to do without checking who asked.

IPC Comparison Summary

If you're choosing rather than cataloguing, start from what you're moving and where it's going:

Picking an IPC mechanism
MechanismLinuxWindowsmacOS
Anonymous pipespipe()CreatePipe()pipe()
Named pipesmkfifo (unidirectional)CreateNamedPipe (bidirectional, networked)mkfifo
Unix socketsAF_UNIXAF_UNIX (Win10+)AF_UNIX
Shared memoryshm_open + mmapCreateFileMappingshm_open + mmap
Message busD-BusCOM/DCOMXPC / NSDistributedNotificationCenter
Kernel commsNetlink, ioctlDeviceIoControlioctl, sysctl, kernel control sockets, IOKit user clients
Platform IPCD-Bus, eventfd, signalfdNamed pipes, mailslots, COM, ALPCMach ports, XPC

Every mechanism here has its sweet spot. Shared memory wins for raw bandwidth on big payloads. Pipes and sockets are dirt-simple and run everywhere. The platform-flavoured stuff (D-Bus, COM, XPC) buys you structured interfaces, service discovery, and built-in access control. Which one fits depends on what you need to move, who's allowed to see it, and which OSes you have to support.