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