Method Short Description Provided by (operating systems
or other environments)
File A record stored on disk, or a record synthesized on demand by a file server, which can be accessed by multiple processes. Most operating systems
Communications file A unique form of IPC in the late-1960s that most closely resembles Plan 9
‘s 9P protocol)
Dartmouth Time-Sharing System
Signal)
; also Asynchronous System Trap
A system message sent from one process to another, not usually used to transfer data but instead used to remotely command the partnered process. Most operating systems
Socket Data sent over a network interface, either to a different process on the same computer or to another computer on the network. Stream-oriented (TCP
; data written through a socket requires formatting to preserve message boundaries) or more rarely message-oriented (UDP
, SCTP
).
Most operating systems
Unix domain socket Similar to an internet socket, but all communication occurs within the kernel. Domain sockets use the file system as their address space. Processes reference a domain socket as an inode
, and multiple processes can communicate with one socket
All POSIX operating systems and Windows 10[3]
Message queue A data stream similar to a socket, but which usually preserves message boundaries. Typically implemented by the operating system, they allow multiple processes to read and write to the message queue
without being directly connected to each other.
Most operating systems
Anonymous pipe A unidirectional data channel using standard input and output
. Data written to the write-end of the pipe is buffered by the operating system until it is read from the read-end of the pipe. Two-way communication between processes can be achieved by using two pipes in opposite “directions”.
All POSIX
systems, Windows
Named pipe A pipe that is treated like a file. Instead of using standard input and output as with an anonymous pipe, processes write to and read from a named pipe, as if it were a regular file. All POSIX systems, Windows, AmigaOS 2.0+
Shared memory) Multiple processes are given access to the same block of memory)
, which creates a shared buffer for the processes to communicate with each other.
All POSIX systems, Windows
Message passing Allows multiple programs to communicate using message queues and/or non-OS managed channels. Commonly used in concurrency models. Used in LPC
, RPC
, RMI
, and MPI
paradigms, Java RMI
, CORBA
, COM
, DDS
, MSMQ
, MailSlots
, QNX
, others
Memory-mapped file A file mapped to RAM
and can be modified by changing memory addresses directly instead of outputting to a stream. This shares the same benefits as a standard file)
.
All POSIX systems, Windows

信号

详见:https://www.yuque.com/bermaker/cs-software/zd7dlm#zI1FQ

管道

管道允许在进程之间按先进先出的方式传送数据,是进程间通信的一种常见方式。
管道是Linux 支持的最初Unix IPC形式之一,具有以下特点:
1) 管道是半双工的,数据只能向一个方向流动;需要双方通信时,需要建立起两个管道
2) 匿名管道只能用于父子进程或者兄弟进程之间(具有亲缘关系的进程);
3) 单独构成一种独立的文件系统:管道对于管道两端的进程而言,就是一个文件,但它不是普通的文件,它不属于某种文件系统,而是自立门户,单独构成一种文件系统,并且只存在与内存中。
管道分为pipe(无名管道)和fifo(命名管道)两种,除了建立、打开、删除的方式不同外,这两种管道几乎是一样的。他们都是通过内核缓冲区实现数据传输。

  • pipe用于相关进程之间的通信,例如父进程和子进程,它通过pipe()系统调用来创建并打开,当最后一个使用它的进程关闭对他的引用时,pipe将自动撤销。
  • FIFO即命名管道,在磁盘上有对应的节点,但没有数据块——换言之,只是拥有一个名字和相应的访问权限,通过mknode()系统调用或者mkfifo()函数来建立的。一旦建立,任何进程都可以通过文件名将其打开和进行读写,而不局限于父子进程,当然前提是进程对FIFO有适当的访问权。当不再被进程使用时,FIFO在内存中释放,但磁盘节点仍然存在。

管道的实质是一个内核缓冲区,进程以先进先出的方式从缓冲区存取数据:管道一端的进程顺序地将进程数据写入缓冲区,另一端的进程则顺序地读取数据,该缓冲区可以看做一个循环队列,读和写的位置都是自动增加的,一个数据只能被读一次,读出以后再缓冲区都不复存在了。当缓冲区读空或者写满时,有一定的规则控制相应的读进程或写进程是否进入等待队列,当空的缓冲区有新数据写入或慢的缓冲区有数据读出时,就唤醒等待队列中的进程继续读写。
image.png

消息队列

消息队列,就是一个消息的链表,是一系列保存在内核中消息的列表。用户进程可以向消息队列添加消息,也可以向消息队列读取消息。
消息队列与管道通信相比,其优势是对每个消息指定特定的消息类型,接收的时候不需要按照队列次序,而是可以根据自定义条件接收特定类型的消息。
可以把消息看做一个记录,具有特定的格式以及特定的优先级。对消息队列有写权限的进程可以向消息队列中按照一定的规则添加新消息,对消息队列有读权限的进程可以从消息队列中读取消息。
进程间通过消息队列通信,主要是:创建或打开消息队列,添加消息,读取消息和控制消息队列。

Shared Memory

In computer science, shared memory is memory that may be simultaneously accessed by multiple programs with an intent to provide communication among them or avoid redundant copies. Shared memory is an efficient means of passing data between programs. Depending on context, programs may run on a single processor or on multiple separate processors.

In computer software, shared memory is either

  1. WikiPedia: Shared memory
  2. WikiPedia: Inter-process communication
  3. 进程间8种通信方式详解