IPC là các cơ chế để các process độc lập trao đổi dữ liệu, vì chúng không chia sẻ bộ nhớ trực tiếp.
- Pipe (anonymous pipe): luồng dữ liệu một chiều giữa parent-child process.
- Named pipe (FIFO): pipe có tên trong filesystem, không cần parent-child relationship.
- Shared Memory: vùng nhớ được map vào address space của nhiều process — nhanh nhất vì không copy data, nhưng cần đồng bộ (mutex/semaphore).
- Message Queue: process gửi/nhận messages qua kernel queue (POSIX mqueue, System V) — asynchronous, có thể buffer.
- Socket: Unix domain socket (local) hoặc TCP/UDP socket (network) — linh hoạt nhất, dùng cả local và remote; microservices giao tiếp qua HTTP/gRPC là IPC qua socket.
- Signal: notification đơn giản (SIGTERM, SIGKILL, SIGUSR1) — limited data.
- Memory-mapped file (mmap): file được map vào memory, nhiều process cùng đọc/ghi — Node.js dùng cho large file processing.
Thực tế: Nginx worker processes giao tiếp với master qua pipe và shared memory.
IPC refers to the mechanisms that allow independent processes to exchange data, since they do not share memory directly.
- Pipe (anonymous pipe): a one-way data stream between a parent and child process.
- Named pipe (FIFO): a pipe with a filesystem name that does not require a parent-child relationship.
- Shared Memory: a memory region mapped into the address space of multiple processes — the fastest mechanism since no data is copied, but requires synchronization (mutex/semaphore).
- Message Queue: processes send and receive messages through a kernel-managed queue (POSIX mqueue, System V) — asynchronous and buffered.
- Socket: Unix domain socket (local IPC) or TCP/UDP socket (network) — the most flexible, supporting both local and remote communication; microservices communicating via HTTP/gRPC are using socket-based IPC.
- Signal: a simple notification mechanism (SIGTERM, SIGKILL, SIGUSR1) — carries no data payload.
- Memory-mapped file (mmap): a file mapped into memory, allowing multiple processes to read and write it concurrently — used in Node.js for large file processing.
In practice, Nginx worker processes communicate with the master process via pipes and shared memory.