Inter-process Communication (IPC) mode

Source: Internet
Author: User
Tags message queue posix semaphore

Why interprocess communication (IPC (inter-process communication))

Data transfer: One process needs to send its data to another process, sending the amount of data between a byte and a few m bytes
Shared data: Multiple processes want to manipulate shared data, one process changes the shared data, and other processes should see it immediately.
Notification Event: A process needs to send a message to another or a set of processes to notify it (they) that an event has occurred (such as notifying the parent process when the process terminates).
Resource sharing: The same resources are shared among multiple processes. In order to do this, the kernel is required to provide a lock and synchronization mechanism.
Process Control: Some processes want to have full control over the execution of another process (such as the debug process), at which point the control process wants to be able to intercept all the sink and exception of another process and be able to know its state changes in a timely manner.

Common ways of communicating between processes in Linux

(1), piping (pipe): Pipelines can be used for inter-process communication, is a half-duplex way, the data can only flow one way, allowing one process and another with its common ancestor of the process to communicate.

(2), named pipe (named pipe): Named pipe overcomes the pipe without the name of the limit, in addition to having the function of the pipeline (also half-duplex), it also allows non-affinity process communication. Named pipes have corresponding file names in the file system. Named pipes are created by command Mkfifo or by system call Mkfifo.

(3), Signal (signal): signal is a more complex mode of communication, to inform the receiving process has some kind of event occurred, in addition to interprocess communication, the process can also send signals to the process itself; Linux in addition to supporting the UNIX early signal semantic function Sigal outside, It also supports the signal function sigaction that is semantically compliant with the POSIX.1 standard (in fact, the function is based on BSD, BSD in order to achieve a reliable signal mechanism, but also can unify the external interface, with the Sigaction function to re-implement the signal function).

(4), Message Queuing: Message Queuing 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 lack of signal carrying information, the pipeline can only carry the unformatted byte stream and the buffer size is limited.

(5), Shared memory: Allows multiple processes to access the same piece of memory space, 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.

(6), Memory Mapping: Memory mapping allows any number of interprocess communication, and each process that uses the mechanism implements it by mapping a shared file to its own process address space.

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

(8), socket (socket): More general inter-process communication mechanism, 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.

Inter-process Communication (IPC) mode

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.