自分の過去メモ(2014年ころ)より
プロセス間の通信手法 (スレッド間通信に使ってもいいとのこと) stackoverflow
- Pipe
- FIFO (named pipe)
- Socket (Unix Domain Socket)
- Message Queue
- Signal
- Semaphore
- Shared memory
- それぞれについて
- Pipe is useful only among processes related as parent/child. Call pipe(2) and fork(2). Unidirectional.
- Two unrelated processes can use FIFO unlike plain pipe. Call mkfifo(3). Unidirectional.
- Bidirectional. Meant for network communication, but can be used locally too. Can be used for different protocol. There's no message boundary for TCP. Call socket(2).
- Message Queue. OS maintains discrete message. See sys/msg.h.
- Signal sends an integer to another process. Doesn't mesh well with multi-threads. Call kill(2).
- Semaphore is a synchronization mechanism for multi processes or threads, similar to a queue of people waiting for bathroom. See sys/sem.h. Shared memory is a shared memory. Do your own concurrency control. Call shmget(2).