named pipe

最後更新: 2018-05-15



A named pipe (also known as a FIFO for its behavior) is an extension to the traditional pipe concept on Unix.

It is one of the methods of inter-process communication (IPC).

A traditional pipe is "unnamed" and lasts only as long as the process.

A named pipe, however, can last as long as the system is up, beyond the life of the process.




# mkfifo - make FIFOs (named pipes)
# -m nnn ( Default: prw-r--r-- ; i.e. -m 600 )


mkfifo MyPipe

Example 1



mkfifo MyPipe

gzip -9 -c < MyPipe > out.gz &


# 只可以行一次

cat file > MyPipe


Example 2



dd if=/dev/zero of=1k bs=1k count=1

# A read call to a FIFO is blocked until a data is available in the pipe and a write call is blocked until the data is read from another process.

cat 1k > MyPipe

The pipe has a 64k buffer (on linux) and, will block the writer when full.



man 7 pipe


Creative Commons license icon Creative Commons license icon