Linux System programming Pipeline (i) anonymous pipes and pipe functions

Source: Internet
Author: User
Tags anonymous

I. Inter-process communication

Each process has a different user address space, the global variables for any one process are not visible in another process, so the data must be exchanged between processes through the kernel, a buffer is created in the kernel, process 1 copies the data from the user space to the kernel buffer, and the process 2 reads the data from the kernel buffer. This mechanism provided by the kernel is called interprocess communication (ipc,interprocess communication). As shown in the following figure.

Second, the pipeline is one of the most basic IPC mechanism, created by the pipe function:

#include <unistd.h>

int pipe (int filedes[2]);

When the pipe function is invoked, a buffer (called a pipe) is used in the kernel to communicate, it has a read end, a write end, and then the Filedes parameter is passed out to the user program two file descriptors, Filedes[0] to the end of the pipe, filedes[1 to the end of the pipe (well remember, Just like 0 is standard input 1 is the same as standard output. So the pipe in the user program looks like an open file, through Read (Filedes[0]), or write (Filedes[1]), and reading and writing to this file is actually read and write to the kernel buffer. The pipe function call returned 0 successfully, and the call failed to return-1.

How do you implement communication between two processes after opening the pipeline? For example, you can follow the steps below to communicate.

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.