Posted on

Named pipe in Linux

Named pipe  (also known as a FIFO for its behavior) is an extension to the traditional pipe concept on Linux/Unix, and is one of the methods of inter-process communication (IPC).

Named pipes may be created using mkfifo() or mknod() and then presented as the input or output file to programs as they are invoked. They allow multi-path pipes to be created, and are especially effective when combined with standard error redirection, or with tee. Two separate processes can access the pipe by name — one process can open it as a reader, and the other as a writer.

For example, you can pipe the output of gzip into a named pipe like so:

mkfifo –mode=0666 /tmp/namedPipe
gzip –stdout -d file.gz > /tmp/namedPipe

Then load the uncompressed data into a MySQL table like:

LOAD DATA INFILE ‘/tmp/namedPipe’ INTO TABLE tableName;

Without this named pipe one would need to write out the entire uncompressed version of file.gz before loading it into MySQL. Writing the temporary file is both time consuming and results in more I/O and less free space on the hard drive.

Leave a Reply

Your email address will not be published. Required fields are marked *