Comprehensive analysis of LINUX open source communication

The process communication method under linux is basically inherited from the process communication method on the Unix platform. The two major AT & T Bell Laboratories and BSD (University of California, Berkeley, Berkeley Software Distribution Center) have made significant contributions to the development of Unix. The former improved and expanded Unix's early inter-process communication methods to form a "system V IPC", and the communication process was limited to a single computer; the latter skipped the restriction and formed a socket-based interface (socket) Inter-process communication mechanism. Linux inherited the two, as shown:

Among them, the original Unix IPC includes: pipeline, FIFO, signal; System V IPC includes: System V message queue, System V semaphore, System V shared memory area; Posix IPC includes: Posix message queue, Posix semaphore, Posix shared memory area. There are two points that need to be briefly explained:

1) Due to the diversity of Unix versions, the Institute of Electrical and Electronics Engineering (IEEE) has developed an independent Unix standard. This new ANSI Unix standard is called a calculation? Fat car head Shao Pu Canyuan Yuan Tong Chen Low Chenjing ≒ SOIX ). Most of the existing Unix and popular versions follow the POSIX standard, while Linux has followed the POSIX standard from the beginning;

2) BSD is not not involved in inter-process communication within a single machine (socket itself can be used for inter-process communication within a single machine). In fact, many Unix versions of stand-alone IPCs leave traces of BSD, such as anonymous memory mapping supported by 4.4BSD, implementation of reliable signal semantics by 4.3 + BSD, and so on.

Brief introduction of several main means of inter-process communication under linux:

1. Pipeline

Pipeline is the oldest way in inter-process communication. It includes two kinds of unnamed pipes and named pipes. The former can be used for communication between related processes, that is, it can be used for communication between parent and child processes. The limitation of the name, therefore, in addition to the function of the former, it also allows communication between unrelated processes, that is, it can be used for communication between any two processes running on the same machine.

Unnamed pipes are created by the pipe () function:

#include

int pipe (int filedis);

The parameter filedis returns two file descriptors: filedes [0] is opened for reading and filedes is opened for writing. The output of filedes is the input of filedes [0].

Under the Linux system, a named pipe can be created in two ways: the command line method mknod system call and the function mkfifo. The following two ways generate a named pipe named myfifo in the current directory:

Method 1: mkfifo ("myfifo", "rw");

Method 2: mknod myfifo p

After the well-known pipeline is generated, you can use general file I / O functions such as open, close, read, and write to operate it.

2. Message Queue

The message queue is a linked list of messages, including the Posix message queue system V message queue. The message queue is used for inter-process communication running on the same machine. It is similar to the pipeline. A process with sufficient authority can add messages to the queue, and a process that is given read permission can read the messages in the queue. The message queue overcomes the shortcomings that the signal carries less information, the pipeline can only carry unformatted byte streams, and the buffer size is limited.

We can replace it with stream pipes or sockets.


Coffee Urn

Commercial Coffee Urn,Coffee Urn,100 Cup Coffee Urn,Large Coffee Urn

FOSHAN FORTUNE ELECTRICAL APPLIANCE CO.,LTD , https://www.coffelady.com