Various ways of inter-process communication between Linux and its comparison

Source: Internet
Author: User

Inter-process communication is the transmission or exchange of information between different processes, so what is there between the different processes that can be accessed by both parties? The user space of the process is independent of each other and is generally inaccessible to each other, with the only exception being the shared memory area . However, the system space is a "public place", so the kernel can obviously provide such conditions. In addition, it is a peripheral that can be accessed by both parties. In this sense, two processes can of course also exchange information through ordinary files on disk, or through "registry" or some table entries and records in other databases. Broadly speaking, this is also a means of inter-process communication, but it is generally not counted as "interprocess communication". Because the efficiency of those communication means is too low, and people's requirements for inter-process communication is to have a certain real-time nature.

Inter-process communication includes pipelines , system IPC ( including Message Queuing , semaphores , shared storage ), SOCKET.

Pipeline consists of three kinds: 1) ordinary pipe pipes , usually have a limit, one half-duplex , only one-way transmission ; the second is that they can only be used between parent and child processes . 2) Flow pipe s_pipe: Remove the first restriction, can be transmitted in both directions. 3) Named pipes : Name_pipe, which removes the second limitation, can communicate between many unrelated processes.

The three ways in which the system IPC is similar are identified using the identifiers in the kernel.

FAQ1: What is the relationship between a pipeline and a file descriptor, a file pointer?

A: In fact, the use of pipelines similar to files, can use Read,write,open and other ordinary IO functions. A pipe descriptor is similar to a file descriptor. In fact, the descriptor used by the pipeline , the file pointer, and the file descriptor will eventually be translated into the system 's SOCKET descriptor . are limited by the socket descriptor in the system kernel. essentially LINUX The kernel source pipeline is through the empty file to implement .

FAQ2: How to use the pipe?

A: There are several methods: 1) pipe, create a pipe, and return 2 pipe descriptors. Typically used for communication between parent-child processes. 2) Popen, Pclose: This method returns only one pipe descriptor, which is often used for communication the other side is Stdinor stdout; 3) Mkpipe: Named pipes that interact with many processes.

FAQ3: What is the comparison between pipeline and system IPC?

A: The advantage is that all UNIX implementations are supported , and after the last access pipeline process terminates, the pipeline is completely deleted; The flaw is that pipelines allow only one-way transmission or between parent-child processes.

System IPC: The advantages are powerful , able to communicate between unrelated processes ; The flaw is that the keyword key_t uses kernel identities, consumes kernel resources, and can only be explicitly deleted , and cannot use some of the socket's mechanisms, such as select,epoll.

Faq4:windos the relationship between interprocess communication and Linux interprocess communication?

A: In fact, most of WinDOS's process communications are ported to UNIX, WinDOS's clipboard, file mappings, and so on, all of which can be found in shared storage for UNIX process communication.

FAQ5: What is the relationship between interprocess communication and inter-thread communication?

A: Because Windows runs on a thread, interprocess communication in the narrow sense refers to the communication between threads belonging to different processes. The thread synchronization problem between individual processes can be merged into a special process communication. It uses the kernel-supported system calls to keep threads synchronized. Some commonly used thread synchronization methods include: Event, Mutex, Semaphore semaphore, critical area resource, and so on.

Comparison of various ways of inter-process communication efficiency

Type

No connection

Reliable

Flow control

Recording

Message type Priority



Various ways of inter-process communication between Linux and its comparison

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.