What is inter-process communication (IPC)?
Answer
Inter-Process Communication (IPC) is the set of mechanisms that allow processes to exchange data and synchronize with each other. Processes have separate memory spaces — they need IPC to communicate. IPC mechanisms: (1) Pipes (anonymous pipes): unidirectional byte stream between related processes (parent-child). int fd[2]; pipe(fd); // fd[0]=read end, fd[1]=write end. Shell: cmd1 | cmd2; (2) Named pipes (FIFOs): pipe with a name in the filesystem — works between unrelated processes: mkfifo /tmp/myfifo; cat /tmp/myfifo & echo "hello" > /tmp/myfifo; (3) Message queues: messages sent to a queue, received by any process with access. Supports selective reading (by message type). POSIX and System V variants; (4) Shared memory: fastest IPC — two processes map the same physical memory into their address spaces. Read/write directly. Requires additional synchronization (semaphores/mutexes): shmget(), shmat(); (5) Sockets: network IPC — works on same machine (Unix domain sockets) or across network (TCP/UDP). Most flexible; (6) Signals: asynchronous notification — one process sends a signal to another: kill(pid, SIGTERM). Limited data (just signal type); (7) Memory-mapped files (mmap): file mapped into memory, shared between processes; (8) D-Bus (Linux): high-level IPC for desktop services. Choosing IPC: related processes + simple → pipes; high throughput → shared memory; across network → sockets; complex messaging → message queues.
Previous
What is a monitor in operating systems?
Next
What is the difference between user mode and kernel mode?