Commonly used inter-process communication

1. Pipe (Pipe) : Pipe can be used for communication between processes that have affinities, allowing communication between a process and another process that has a common ancestor with it.
2. Named pipe : Named pipe overcomes the limitation that the pipe has no name. Therefore, in addition to the functions of the pipe, it also allows communication between unrelated processes. Named pipes have corresponding file names in the file system. The named pipe is created by the command mkfifo or the system call mkfifo.
3. Signal (Signal) : Signal is a more complex communication method, used to notify the receiving process that a certain event has occurred. In addition to inter-process communication, the process can also send a signal to the process itself.
4. Message (Message) queue : Message queue is a linked list of messages, including Posix message queue system V message queue. Processes with sufficient permissions can add messages to the queue, and processes with read permissions can read messages in the queue. The message queue overcomes the shortcomings of the signal carrying less information, the pipe can only carry an unformatted byte stream, and the limited buffer size. The message queue is record-oriented, and the messages in it have a specific format and a specific priority. The message queue is independent of the sending and receiving processes. When the process is terminated, the message queue and its contents will not be deleted. The message queue can realize random query of messages. Messages do not have to be read in a first-in first-out order, but can also be read according to the message type.
5. Shared memory : allows multiple processes to access the same memory space, which is the fastest form of IPC available. It is designed for the low efficiency of other communication mechanisms. It is often used in combination with other communication mechanisms, such as semaphores, to achieve synchronization and mutual exclusion between processes. Need to be synchronized.
6. Semaphore: Mainly used as a means of synchronization between processes and between different threads of the same process. To transfer data between processes, it is necessary to combine shared memory. The semaphore is based on the PV operation of the operating system, and the operations of the program on the semaphore are all atomic operations. Each PV operation on the semaphore is not limited to adding 1 or subtracting 1 to the semaphore value, and can add or subtract any positive integer. Support semaphore group.
7. Socket (Socket) : A more general inter-process communication mechanism that can be used for inter-process communication between different machines. It was originally developed by the BSD branch of the Unix system, but now it can generally be ported to other Unix-like systems: both Linux and System V variants support sockets.

Guess you like

Origin blog.51cto.com/14289397/2540762