Linux interprocess communication (IPC)

Source: Internet
Author: User
Tags message queue mutex posix semaphore

I. Overview of inter-process communicationprocess Communication has for example some of the following purposes:
A, transfer data: A process needs to send its data to another process. The amount of data sent is between one byte and a few m bytes
B, shared data: Multiple processes want to manipulate shared data. A process changes the shared data, and other processes should see it immediately.
C, notification event: A process needs to send a message to a process or group of processes. Notifies it (they) that an event has occurred (such as notifying the parent process when the process terminates).
D, resource sharing: Multiple processes share the same resources. In order to do this, the kernel is required to provide a lock and synchronization mechanism.

E, Process Control: Some processes want complete control over the running of a process (such as the debug process). At this point the control process wants to intercept all the sinking and exceptions of a process. And can know its status change in time.


There are many ways to communicate with the local interprocess communication (IPC). But can be summed up in the following 4 categories:
A, Message delivery (pipeline, FIFO, Message Queuing)
B, synchronization (mutual repulsion amount, condition variable, read/write lock, file and write record lock, semaphore)
C, shared memory (anonymous and named)
D, remote procedure calls (Solaris Gate and Sun RPC)


second, the process communication under Linux is basically inherited from the process communication means on the UNIX platform.

The two main at-and-T Labs and BSD (UC Berkeley's Berkeley Software Publishing Center), which make a major contribution to UNIX development, have a different focus on interprocess communication. The former has systematically improved and expanded the process of communication between the early stages of UNIX, and formed the "system V IPC". the communication process is confined to a single computer . The latter skips the limit. An inter-process communication mechanism based on socket (socket) is formed, and the communication process is within a computer within the same network .

Linux has inherited both.


System V IPC includes: System V Message Queuing, System V Semaphore, System v shared memory area;

The original UNIX IPC contains: pipelines, FIFO, signal.

POSIX IPC contains: POSIX Message Queuing, POSIX semaphores, POSIX shared memory area.

There are two points that need to be explained briefly:

1) Because of the diversity of UNIX version numbers, the Electronic and Electrical Project Association (IEEE) has developed a standalone UNIX standard, a new ANSI UNIX standard called the Portable Operating System interface (POSIX) for the computer environment.

Most of the existing UNIX and popular version numbers follow the POSIX standard. And Linux follows the POSIX standard from the start;

2) BSD is not involved in interprocess communication within a single machine (the socket itself can be used for interprocess communication within a single machine).


Third, Linux under the process of communication between the main means of simple introduction:

  1. Pipe and well-known pipe (named pipe): Pipelines can be used for communication between affinity processes, and famous pipelines overcome the limitations of piping without names. So. In addition to having the functions of a pipeline, it also agrees that communication between unrelated processes is not involved;

  2. Signal (Signal): signal is a more complex mode of communication. Used to inform the receiving process that an event occurred, in addition to interprocess communication, the process can send signals to the process itself; Linux supports the sigaction of signal functions that conform to the POSIX.1 standard, in addition to supporting UNIX early signal semantic function Sigal. The function is based on BSD, BSD in order to achieve a reliable signal mechanism, but also can unify the external interface, with sigaction function once again implemented signal function).

  3. message queue: Message Queuing is a linked table of messages that contains POSIX Message Queuing system V Message Queuing.

    A process with sufficient permissions can add messages to the queue. The process that is given Read permission is able to read the messages in the queue.

    Message queue overcomes the shortcoming that the signal carrying information is small, the pipeline can only carry the unformatted byte stream and the buffer size is limited.

  4. Shared memory: Enables multiple processes to access the same piece of memory space, which is the fastest available IPC form. is designed for inefficient execution 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.

  5. Semaphore (semaphore): primarily as a means of synchronization between processes and between different threads of the same process.

  6. 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 is now generally possible to migrate to other Unix-like systems: both Linux and System V variants support sockets.

Note:

Linux interprocess communication: Pipeline, Signal, semaphore, message queue, shared memory, socket (socket)

Linux inter-thread communication: The amount of mutual repulsion (mutex), semaphore. Condition variable

Windows interprocess communication: Pipeline, Message Queuing, shared memory, Semaphore (semaphore), socket (socket)

Windows inter-thread communication: Mutual repulsion Amount (mutex), Semaphore (semaphore), critical section (critical), event


Linux interprocess communication (IPC)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.