Deep understanding communication between Linux processes (IPC)
content:
Preface to the author
In the Linux area:
Tutorial Tools & Product Codes & Component Articles
Zheng Yanxing (mlinux@163.com) November 2002
A large application system often requires many process collaborations, and the importance of communication between the process (Linux process concept is attached) is obvious. This series describes several main processes in the Linux environment, and gives a detailed example of the key technology links for each communication means. In order to achieve the purpose of clarify the problem, this paper also analyzes the internal implementation mechanism of certain communication methods.
The process communication method under the order Linux is basically inherited from the process communication means from the UNIX platform. The two major AT & T of UNIX development, the Bel Laboratory and BSD (the Berkeley Software Release Center of California University Berkeley) have different focuses on communication between processes. The former has improved and expanded the system of the process between the early process of UNIX, forming "System V IPC", the communication process is limited to a single computer; the latter skips the limit, forming a socket (socket) Inter-process communication mechanism. Linux inherits the two, as shown:
Among them, the initial UNIX IPC includes: pipe, FIFO, signal; System V IPC includes: System V message queue, System V signal, System V shared memory area; POSIX IPC includes: POSIX message queue, POSIX signal, POSIX shared memory area. There are two points to briefly explain: 1) Due to the diversity of UNIX, the Electrical Engineering Association (IEEE) has developed a separate UNIX standard, which is called a computer environment's portability operating system interface. (PSoix). Most UNIX and popular versions are followed by POSIX standards, while Linux follows POSIX standards from the beginning; Communication). In fact, many UNIX versions of single IPC have traces of BSD, such as anonymous memory mapping supported by 4.4BSD, 4.3 BSD implementation of reliable signal semantics, and more. Figure 1 gives various IPC means supported by Linux, in this article, in order to avoid conceptual confusion, all questions discussions will eventually be attributed to all versions of UNIX as little as possible. Inter-process communication in the Linux environment. Also, for different implementation versions of Linux support (such as for shared memory, there are two implementation versions of the POSIX shared memory area and the System V shared memory area), the POSIX API will mainly introduce the POSIX API. Several main means of communication between processes under Linux:
Pipe (PIPE) and a named PIPE: The pipe can be used in communication between the processes, and the famous pipe overcomes the limitations of the pipeline without the name, and therefore, it also allows no physical relationships in addition to the function of the pipe. Communication between processes; signal (Signal): The signal is a complicated communication method, which is used to notify the accepted process. There is a certain event. In addition to the inter-process communication, the process can also send a signal to the process itself; Linux In addition to support UNIX In addition to the early signal semantic function Sigal, the Semantic Signal Function Sigaction is also supported in line with the POSIX.1 standard (actually, the function is BSD based on BSD, and BSD can unify the external interface, and re-implement Signal with the SIGNAL in the external interface. Function); Message queue (message queue): Message queue is a message linked table, including the POSIX message queue SYSTEM V message queue. Process with sufficient permissions can add messages to the queue, which is given to the read permissions, can read the messages in the queue. The message queue overcomes the amount of signal carrying information, and the pipeline can only carry a shortcoming of unformatted byte streams and the size of the buffer size. Share memory: Make multiple processes to access the same memory space, is the fastest available IPC form. It is designed for other communication mechanisms. Other communication mechanisms, such as signal volume, to reach synchronization and mutual exclusion between processes. Semaphore: The synchronization method between the process between the processes and the different threads of the process and the same process. Socket: More general process communication mechanisms can be used in inter-process communication between different machines. At first, it was developed by the BSD branch of the UNIX system, but it is now generally ported to other class UNIX systems: the variants of Linux and System V support sockets. The above communication mechanism will be specifically described below. Attached 1: References [2] Summary of the process in the Linux environment: In general, Linux processes the following key elements: There is an executable program; there is a dedicated system stack space; kernel With its control block (process control block), describe the resources occupied by the process, so that the process can accept the scheduling of the kernel; with independent storage space processes and threads sometimes not distinguish, and often understand its meaning according to the context. references: