Direct RAM access. Zero kernel involvement. Fastest IPC mechanism on a single host.
0 copies0 syscalls
Pipe
Unidirectional kernel buffer. Data passes through kernel space — two copies per message.
2 copies2 syscalls
Unix Socket
Full-duplex socket in filesystem. Same overhead as pipes, but bidirectional communication.
2 copiessame-host
TCP Socket
Full network stack. Checksums, retransmits, sequence numbers. Works cross-host.
3+ copiescross-host
Benchmark
Race all four mechanisms side-by-side. 100k messages. See the tradeoffs clearly.
compare all
Shared Memory
Writer
pid 12340
idle
Reader
pid 12341
idle
// shared memory
seq—
data—
readyfalse
0 / 10 messages
—
Metrics
Copies / msg0
Syscalls / msg0
Kernel involvedNo
Avg latency—
Throughput—
Event log
No kernel transition. Writer maps memory, reader maps same region. No copying — both see the same physical RAM.
Pipe
Parent
pid 12340
idle
Child
pid 12341
idle
kernel · pipe buffer
—
—
—
—
—
—
0 / 10 messages
—
Metrics
Copies / msg2
Syscalls / msg2
Kernel involvedYes
Avg latency—
Throughput—
Event log
write() copies data into kernel buffer. read() copies out. Two mandatory kernel transitions per message — that's the isolation cost.
Unix Socket
Server
pid 12340
idle
Client
pid 12341
idle
/tmp/ipc.sock
⇄ full duplex
0 msgs sent
0 / 10 messages
—
Metrics
Copies / msg2
DirectionBidirectional
Cross-hostNo
Avg latency—
vs pipe—
Event log
Same kernel overhead as a pipe, but bidirectional. Both peers can send and receive on the same socket. Stays on-machine.
TCP Socket
Server
:8080
idle
Client
127.0.0.1
idle
Socket API
send/recv
TCP Layer
seq · checksum
IP · Loopback
lo interface
0 / 10 messages
—
Metrics
Copies / msg3+
Syscalls / msg3+
Cross-hostYes
Avg latency—
vs shm—
Event log
Most overhead: TCP seq tracking, checksum computation, ACK round-trip. Even on loopback, the full network stack runs.
Benchmark · 100k messages · 64 bytes
shm
—
pipe
—
unix sock
—
tcp
—
Mechanism
Copies
Syscalls
Latency
Use when
Shared memory
0
0
~0.002ms
max speed
Pipe
2
2
~0.04ms
simple IPC
Unix socket
2
2
~0.05ms
bidirectional
TCP
3+
3+
~0.15ms
cross-host
Summary
FastestShared mem
SHM vs TCP~75×
SHM vs Pipe~18×
Pipe vs Unix~similar
Faster ≠ always better. Shared memory has no isolation — a bug in either process can corrupt the shared region. TCP adds retransmit,
ordering, and network portability. Choose by your real constraints.