Inter-process communication (IPC)

Source: Internet
Author: User

Why communication between processes (IPC (inter-process communication ))

Data transmission: A process needs to send its data to another process. The data volume sent is between one byte and several Mb.
Share Data: multiple processes want to operate on shared data. If a process modifies the shared data, other processes should immediately see it.
Notification event: a process needs to send a message to another process or a group of processes to notify it of an event (for example, to notify the parent process when the process is terminated ).
Resource Sharing: multiple processes share the same resource. To achieve this, the kernel needs to provide a lock and synchronization mechanism.
Process control: some processes want to completely control the execution of another process (such as the debug process). At this time, the control process wants to block all the traps and exceptions of another process, and be able to know its status changes in time.

Common inter-process communication methods in Linux

(1) pipeline (PIPE): pipeline can be used for communication between kinship processes. It is a half-duplex method, and data can only flow in one way, allows one process to communicate with another process that has a common ancestor with it.

(2) Named Pipe (Named Pipe): The Named Pipe overcomes the pipe's no-name restriction. Besides the pipe's function (also half-duplex ), it also allows communication between unrelated processes. The named pipe has a corresponding file name in the file system. The named pipe is created by running the mkfifo command or by calling the mkfifo command.

(3) signal: a signal is a complex communication method used to notify the receiving process of an event. Besides inter-process communication, the process can also send signals to the process itself. In addition to supporting the sigal function of the early UNIX signal semantics, Linux also supports the sigaction function of the posix.1 standard. (In fact, this function is based on BSD, BSD re-implements the signal function with the sigaction function in order to implement a reliable signal mechanism and unify external interfaces ).

(4) Message Queue: Message Queue is a chain table of messages, including POSIX Message Queue System V message queue. A process with sufficient permissions can add messages to the queue. A process with the read permission can read messages from the queue. Message Queue overcomes the limitations of insufficient signal carrying information, and pipelines can only bear unformatted byte streams and limited buffer size.

(5) shared memory: Enables multiple processes to access the same memory space, which is the fastest available IPC form. It is designed to reduce the running efficiency 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 ing: Memory ing allows communication between any process. Every process using this mechanism maps a shared file to its own process address space.

(7) semaphores (semaphore): used for synchronization between processes and between different threads of the same process.

(8) socket: a more general inter-process communication mechanism that can be used for inter-process communication between different machines. It was initially developed by the BSD branch of the UNIX system, but now it can be transplanted to other UNIX-like systems: both Linux and System V variants support sockets.

 

 

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.