Inter-Process Communication # # Linux # pipe (pipe) - Named Pipes fifo

Named pipes (named pipe) is also known as FIFO queue (the FIFO), is a special pipe, is present in the file system. Named pipes and pipes is very similar, but there are a significant feature of its own:

  • Named pipes can be used in any communication between two processes, not limited to two processes homologous.
  • Named Pipes as a special file stored in the file system, rather than stored in the kernel image pipeline. After the end of the process of using named pipes, named pipes still exists in the file system unless you delete them, otherwise the named pipe will not go away.

And pipeline as named pipes can only be used for one-way transmission of data, if the named pipe to use two-way transmission of data between two processes, it is recommended to use two-way named pipes.

Mkfifo through the command line or mknod command to create a named pipe:

int mkfifo(const char *pathname, mode_t mode);

 

  • pathname: a string pointer is used to store the file path of the named pipe.
  • mode: used to represent a specified permission to create the file. S_IFIFO | 0666 ;
  • Return 0 on success; returns -1 if the call fails.
     
int mknod(char *pathname, mode_t mode, dev_t dev);
  • pathname: a string pointer is used to store the file path of the named pipe.
  • mode: used to represent a specified permission to create the file. S_IFIFO | 0666 ;
  • Incoming 0:00 create a common file type for the S_IFCHR or S_IFBLK when the file only device number,: dev_t. When you can create a named pipe, the third argument dev passing 0 indicates that the file is not a device file.
  • Return 0 on success; returns -1 if the call fails.

 

At this point, let's review the differences in three pipeline again

 

Published 170 original articles · won praise 207 · Views 4.59 million +

Guess you like

Origin blog.csdn.net/xiaoting451292510/article/details/103730994