Pipelines for inter-process communication and named pipelines in Linux
Source: Internet
Author: User
In Linux, the inter-process communication pipeline and the named pipeline-Linux general technology-Linux programming and kernel information are described below. Pipelines and famous Pipelines
In this series, the author outlines several main methods for inter-process communication in linux. Among them, pipelines and named pipelines are one of the earliest inter-process communication mechanisms. pipelines can be used for inter-process communication with kinship. Famous pipelines overcome the restrictions that pipelines do not have names, in addition to the functions of pipelines, it also allows communication between unrelated processes. Recognizing the read and write rules of pipelines and named pipelines is the key to applying them in programs. This article discusses in detail the communication mechanism of pipelines and named pipelines, the instance is used to verify its read/write rules by program. This helps to enhance the reader's perceptual knowledge of the read/write rules, and also provides application examples.
1. Pipeline overview and related API applications
1.1 key concepts related to pipelines
As one of the first Unix IPC formats supported by Linux, pipelines have the following features:
The pipeline is half-duplex, and data can only flow in one direction. when both parties need to communicate, two pipelines need to be established;
It can only be used between parent and child processes or sibling processes (kinship processes );
An independent file system is formed: An MPs queue is a file for processes at both ends of the MPs queue, but it is not a common file. It does not belong to a file system, but a self-built portal, A file system exists only in memory.
Data Reading and Writing: The content written by a process to the pipeline is read by the process at the other end of the pipeline. The written content is added at the end of the MPs queue buffer, and data is read from the buffer header each time.
1.2 create an MPS queue:
# Include
Int pipe (int fd [2])
The two ends of the pipeline created by this function are in the middle of a process, which does not make much sense in actual application. Therefore, after a process creates a pipeline by pipe (), it generally fork another sub-process, then, the communication between parent and child processes is realized through the pipeline (so it is not difficult to launch. As long as there is a kinship between the two processes, the kinship here refers to a common ancestor, you can use pipelines for communication ).
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