Capacity and internal organization of Linux pipelines

Source: Internet
Author: User

1. Pipe capacity count=65536, i.e. 64KB

#include <stdio.h> #include <sys/types.h> #include <unistd.h> #include <fcntl.h> #include < errno.h> #include <stdlib.h> #include <string.h>int main () {    int _pipe[2];    if (pipe (_pipe) ==-1)    {        printf ("Pipe error\n");        return 1;    }    int ret;    int count=0;    int Flag=fcntl (_PIPE[1],F_GETFL);    Fcntl (_pipe[1],f_setfl,flag| O_nonblock);    while (1)    {        ret=write (_pipe[1], "A", 1);        if (ret==-1)        {            printf ("Error%s\n", Strerror (errno));            break;        }        count++;    }    printf ("count=%d\n", count);    return 0;}

2. Internal organization of Pipelines

   In Linux, the implementation of pipelines does not use a dedicated data structure, but instead uses the file structure of the filesystem and the index node inode of the VFS. By pointing two file structures to the same temporary VFS index node, the VFS index node points to a physical page.

There are two file data structures, but they define file operation routines where the address is different, one is a routine address that writes data to the pipeline, and the other is a routine address that reads data from the pipeline. In this way, the system call of the user program is still the usual file operation, but the kernel uses this abstraction mechanism to realize the special operation of the pipeline.

Capacity and internal organization of Linux pipelines

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.