Piping is the most basic IPC mechanism, created by the pipe function:
#include <unistd.h>?
int pipe (int filedes[2]);
When the pipe function is called, a buffer (called a pipe) in the kernel is used for communication, it has a write end to the read end, and is then passed out to the user via the Filedes parameter
Program two file descriptor, Filedes[0] point to the read end of the pipe, filedes[1] points to the write end of the pipe (very well, as if 0 is the standard output 1 is the standard output? sample).
So the pipeline in the user program looks like an open file, via read (Filedes[0]), or write (filedes[1]); Read and write data to this file actually
is in the read-write kernel buffering area. The pipe function call successfully returned 0, and the call failed to return-1.
The process of using pipelines for interprocess communication:
1. The parent process calls pipe to open a pipeline and gets two file descriptors pointing at both ends of the pipeline.
2. The parent process calls fork to create the child process, then the child process also has two?
3. The parent process closes the pipe read end, and the child process closes the pipe write end. The parent process can write to the pipeline, the child process can be read from the pipeline, the pipeline is implemented by the ring queue, the number
From the write-side inflow from the read-side outflow, so that the interprocess communication.
Capacity of the pipe:
Method One: Use Linux's ulimit-a to view system limits:
So the size of one atom input is: 512Byte * 8=4096byte;
To view the number of buffer entries: cat/usr/src/kernels/3.10.0-327.el7.x86_64/include/linux/pipe_fs_i.h file,
found that there are 16 buffer entries, and then calculated the capacity of the pipeline size: 16*4096byte=64kb;
Method Two: We can also check the manual: Man 7 Pipe query capacity pipe capacity:
Method Three: Use the program to calculate the capacity of the pipeline:
The running results show:
So the capacity of the pipeline is 65535/1024=64kb;
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 of
file data structures, but they define files with a different operation routine address, one of which is a routine address that writes data to the pipeline, and the other one is from the tube
the sample address of the data read out in the Tao. In this way, the system call of the user program is still the usual file operation, and the kernel uses this abstract machine to implement the pipe
The special operation of the road.
linux--Piping Pipe