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
- Anonymous pipes PIPE : stored in the kernel, can only be used between parent and child or sibling processes.
- Standard flow conduit pipe : for anonymous pipes PIPE series of packages. Returns the file stream.
- Named Pipes the FIFO : a special type of files stored in the file system, can communicate between many processes are not related.