Order
The process communication methods under Linux are basically inherited from the process communication methods on the UNIX platform. The two main players at T-Lab and BSD (UC Berkeley's Berkeley Software Release Center), which have made significant contributions to the development of UNIX, have a different focus on interprocess communication. The former makes a systematic improvement and expansion of the inter-process communication means of UNIX, which forms the "system V IPC", the communication process is confined to a single computer, the latter skips the limit and forms the inter-process communication mechanism based on socket. Linux has inherited the two, showing:
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 Queuing, POSIX semaphore, POSIX shared memory area. There are two points to be brief: 1) due to the diversity of UNIX versions, the Institute of Electrical and Electronic Engineering (IEEE) has developed a standalone UNIX standard, a new ANSI UNIX standard called the Portable Operating System interface (POSIX) of the computer environment. Most of the existing UNIX and popular versions follow the POSIX standard, and Linux adheres to the POSIX standard from the start, and 2) BSD is not a non-interprocess communication within a single machine (the socket itself can be used for interprocess communication within a single machine). In fact, many UNIX versions of the stand-alone IPC are left with BSD traces, such as the 4.4BSD supported anonymous memory mapping, the implementation of 4.3+BSD for reliable signal semantics, and so on.
Figure one gives the various IPC methods supported by Linux, and in the next discussion of this article, in order to avoid conceptual confusion, the discussion of all problems will end up in the process of communication in the Linux environment, with as little reference as possible to the various versions of UNIX. Also, the POSIX API is primarily introduced for different implementations of the communication means supported by Linux, such as the POSIX shared memory area and the two implementation versions of the System V shared memory area for shared memory.
Introduction to several main means of interprocess communication under Linux:
- Pipe and well-known pipe (named pipe): Pipelines can be used for communication between affinity processes, and well-known pipelines overcome the limitations of pipe without name, so that, in addition to having the functions of a pipeline, it allows communication between unrelated processes;
- Signal (Signal): signal is a more complex mode of communication, used to inform the receiving process of an event occurred, in addition to inter-process communication, the process can also send signals to the process itself; Linux in addition to supporting early UNIX signal semantic function Sigal, Also support the semantics of the POSIX.1 standard signal function sigaction (in fact, the function is based on BSD, BSD in order to achieve a reliable signal mechanism, but also able to unify the external interface, with sigaction function to re-implement the signal function);
- Message queue (Message Queuing): Messages queue is a linked table of messages, including POSIX Message Queuing system V Message Queuing. A process with sufficient permissions can add messages to the queue, and a process that is given Read permission can read the messages in the queue. Message queue overcomes the disadvantage that the signal carrying information is low, the pipeline can only carry the unformatted byte stream and the buffer size is limited.
- Shared memory: Allows multiple processes to access the same piece of memory space and is the fastest available IPC form. is designed for inefficient operation of other communication mechanisms. It is often used in conjunction with other communication mechanisms, such as semaphores, to achieve synchronization and mutual exclusion between processes.
- Semaphore (Semaphore): primarily as a means of synchronization between processes and between different threads of the same process.
- Socket: A more general inter-process communication mechanism that can be used for inter-process communication between different machines. Originally developed by the BSD branch of the UNIX system, it can now be ported to other Unix-like systems: both Linux and System V variants support sockets.
The above communication mechanism will be described in detail.
Attached 1: reference [2] provides a summary of the processes in the Linux environment:
In general, the processes under Linux contain several key elements:
- There is an enforceable procedure;
- There is a dedicated system stack space;
- The kernel has its control block (Process Control block), which describes the resources occupied by the process, so that the process can accept the kernel scheduling;
- has separate storage space
Processes and threads are sometimes not completely differentiated, and often understand their meaning in terms of context.
Resources
- UNIX environment Advanced Programming, W.richard Stevens, translator: Yu Jinyuan, Machinery Industry press. Has rich programming examples, and the key function accompanies the development process of UNIX.
- Linux kernel Source-code scenario analysis (top, bottom), Maudeca, Hu Himing, Zhejiang University Press, provides a very good analysis of the Linux kernel, while the background of some key concepts are described in detail.
- UNIX Network Programming Volume II: Interprocess communication, W.richard Stevens, translator: Yang Jizhang, Tsinghua University Press. A more comprehensive description of the process of communication between the UNIX environment of the book (No Signal and socket interface, the socket in the first volume).
From
Http://www.ibm.com/developerworks/cn/linux/l-ipc/index.html
Unix/linux interprocess communication (IPC)--Overview