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

 

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

i.e.

mkfifo MyPipe


Example 1

 

A:

mkfifo MyPipe

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

B:

# 只可以行一次

cat file > MyPipe

 

Example 2

 

A:

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.

 


Doc

man 7 pipe

 

Creative Commons license icon Creative Commons license icon