SwadhyAI Notes

All Operating Systems notes

Start here

IPC = inter-process communication. Pick primitives based on latency, security boundary, ordering, and whether you need persistence beyond process lifetime.

IPC families

Byte streams (pipes, TCP, Unix stream sockets) deliver ordered bytes; you must add framing. Shared memory offers the lowest latency bulk path but requires explicit synchronization. Signals are coarse notifications, not a data plane. Higher layers (DBus, Kafka) add naming, policy, and durability.

By the end of this page you should be able to

  1. Contrast stream IPC vs message boundaries.
  2. Explain why Unix domain sockets are often used locally instead of TCP loopback.
  3. Name one capability Unix sockets can pass besides bytes.

Operating systems · Processes

Inter-process communication overview

Pipes, sockets, shm, signals, message queues

TL;DR

IPC mechanisms differ by semantics: byte streams (pipes, TCP), message boundaries (UDP, MQs), shared memory with explicit sync, and asynchronous notifications (signals). The kernel mediates security (permissions, namespaces) and performance (zero-copy paths, splice, sendfile).

Summary

Pick IPC like you pick storage: match durability, ordering, throughput, and failure semantics. OS courses emphasize mechanisms; interviews want tradeoffs and failure modes (backpressure, partial reads, EPIPE).

Diagram

Use this as the picture you would redraw from memory after closing the tab.
Diagram text: the exact Mermaid definition below preserves the nodes, labels, and connections. Enable JavaScript to view the rendered diagram.
Read the diagram definition
flowchart TB
  subgraph kernel[Kernel IPC]
    P[pipe/socket buffer]
    M[shm + page cache]
  end
  A[Process A] --> P
  B[Process B] --> P
  A --> M
  B --> M

Deeper narrative

IPC spans anonymous pipes, named FIFOs, Unix domain sockets (credentials SCM_RIGHTS), shared memory, signals, and higher-level buses (DBus, Kafka). Pick based on latency, security boundary, ordering, and persistence requirements.

Mechanism (step by step)

Treat each step as a sentence in the story you tell on a whiteboard.
1

Byte-stream IPC

Pipe/socket pair with kernel buffer; natural flow control via blocking.

2

Shared memory

Map same frames into multiple VAS; requires explicit synchronization.

3

Message queues / RPC

Kernel or userspace brokers with typed messages and acknowledgements.

4

Signals

Asynchronous notifications, not a general data plane but coordination primitive.

Key insights

Each card is a compression of the lesson, use them as spaced-repetition prompts.

Capability passing

SCM_RIGHTS and `pidfd` APIs show IPC as capability transfer, not only data copy.

Namespace isolation

Network namespaces mean “localhost IPC” is not global, debugging distributed systems on one host uses veth pairs.

Performance ladder

Copying < shared memory + atomics < ring buffers in userspace with kernel bypass (advanced NIC/GPU paths).

Security boundaries

Unix permissions + SELinux labels gate who can connect to a domain socket path.

Did you know?

Trivia with teeth: the kind of fact that changes how you reason about a design.
`memfd_create` lets anonymous shared memory with sealing, sandboxing trick used by browsers.
Signals are a blunt IPC tool, async, limited payload, easy to mishandle; prefer explicit channels for complex protocols.
eBPF now allows programmable IPC/tracepoints without loading kernel modules.

Common pitfalls

Where smart people still trip, read slowly.

Underspecified message boundaries

Stream sockets need framing; TCP is byte stream not message stream.

SCM_RIGHTS lifetime

Passing fds requires understanding reference counts and CLOEXEC races.

Comparison

IPC snapshot

MechanismTypical use
PipeParent/child or sibling processes streaming bytes
Unix domain socketLocal RPC with permissions on filesystem path
TCP socketCross-machine ordered byte stream
Shared memory + mutexHigh-throughput shared state

Glossary

UDS

Unix domain socket, kernel IPC endpoint with filesystem path or abstract name.

SCM_RIGHTS

Control message passing file descriptors between processes over socket.

memfd

Anonymous memory-backed file usable for sealed shared regions or sandboxing.

Interview follow-ups

  1. Why are Unix domain sockets faster than TCP loopback for local IPC?
  2. How does `memfd_create` relate to IPC?
  3. What guarantees does POSIX message queue provide vs Kafka?

Callouts

Debugging

`lsof -p PID` reveals IPC endpoints quickly on Linux.

Walkthrough & deep dive

Left: practical “how would I use this?” threads. Right: slower, code-leaning explanations, open one panel at a time so the page does not feel like a wall of sameness.

Walkthrough

Design drill

Choose IPC for: (1) browser tab to GPU process, (2) two microservices on same host, (3) cross-region replication.

Deep dive

Broken pipe semantics

Writing to a pipe with no readers raises SIGPIPE/EPIPE, servers must handle client disconnects.

List IPC for a PID

Terminal
lsof -p $ | head

Self-check

Misses here are cheap; misses in an interview are not. Treat wrong answers as a patch list for tomorrow.

1Unix domain sockets can…

2Pipes provide…

3Signals are weak for IPC because…