Linux Interprocess Communication

Overview of Interprocess Communication
Process communication has the following purposes:
A. Data transmission: One process needs to send its data to another process, and the amount of data sent is between one byte and several Mbytes.
B. Shared data: more If a process wants to operate on shared data, changes to shared data by one process should be seen by other processes immediately.
C. Notification events: A process needs to send a message to another or a group of processes to notify it (them) that some event has occurred (such as notifying the parent process when the process terminates).
D. Resource sharing: The same resources are shared among multiple processes. To do this, the kernel needs to provide locking and synchronization mechanisms.
E. Process control: Some processes want to completely control the execution of another process (such as the Debug process). At this time, the controlling process hopes to intercept all traps and exceptions of another process, and be able to know its state changes in time.
Linux inter-process communication (IPC) developed in several parts:
early UNIX inter-process communication, System V-based inter-process communication, Socket-based inter-process communication and POSIX inter-process communication.
UNIX inter-process communication methods include: pipes, FIFOs, and signals.
System V inter-process communication includes: System V message queue, System V semaphore, System V shared memory,
POSIX inter-process communication includes: posix message queue, posix semaphore, and posix shared memory.

Eight methods of process communication under Linux: pipe, named pipe (FIFO), mapped memory, message queue, shared memory, semaphore, signal ), socket (Socket)
    (1) Pipe: A pipe allows communication between one process and another process that has a common ancestor with it;
    (2) Named pipe (FIFO): Similar to a pipe, but it can be used between any two processes For communication between, named pipes have corresponding file names in the file system. Named pipes are created by the command mkfifo or the system call mkfifo;
    (3) Signal (signal): Signal is a relatively complex communication method used to notify the receiving process that something has happened. In addition to being used for inter-process communication, processes can also Send a signal to the process itself; in addition to supporting the UNIX early signal semantic function signal, Linux also supports the signal function sigaction whose semantics conform to the POSIX.1 standard (actually, this function is based on BSD, which can implement a reliable signal mechanism and Unify the external interface and re-implement the function of the signal function with the sigaction function);
    (4) Mapped memory: Memory mapping allows communication between any number of processes, and each process using this mechanism maps a shared file by mapping it. to its own process address space to implement it;
    (5) message queue (message queue): message queue is a connection table of messages, including POSIX message pairs and System V message queues. Processes with sufficient permissions can add messages to the queue, and processes granted read permissions can read messages from the queue. The message queue overcomes the shortcomings of the small amount of information carried by the signal, the pipeline can only be the unformatted byte stream and the buffer size is limited;
    (6) semaphore (semaphore): semaphore is mainly used between processes and between different threads of the same process. (7) Shared
    memory (shared memory): It enables multiple processes to access the same memory space and is the fastest form of IPC available. This is designed for other communication mechanisms to operate less efficiently. It is often used in conjunction with other communication mechanisms, such as semaphores, to achieve synchronization and mutual exclusion between processes;
    (8) Socket: It is a more general inter-process communication mechanism that can be used for inter-process communication between different machines. Originally developed by the BSD fork of UNIX systems, it is now generally portable to other UNIX-like systems: Linux and System V variants both support sockets.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326429659&siteId=291194637