There's nothing difficult to understand about named pipes. To create a pipe named mypipe, Open a virtual terminal and type
mkfifo mypipe
This creates a named pipe in the current directory. (Presumably your home directory since you just opened a virtual terminal). Now type
ls > mypipe
Nothing seems to have happened, except your terminal seems hung. Now open another virtual terminal, or even log into a console and type
cat < mypipe
and you should see the contents of your directory
That's called inter process communication (IPC). One very useful application of named pipes is to allow totally unrelated programs to communicate with each other.
The pipe, like most everything else in Unix, is a file and can be seen with
ls -lF mypipe
The type is p for pipe and the classification symbol is |
prw-r--r-- 1 user user 0 2009-12-10 06:26 mypipe|
The pipe will persist until you delete it
rm mypipe
If you want the pipe to have different permissions, there is an option for that
mkfifo -m a+w pipe
The mode to give is the same as for chmod
prw-rw-rw- 1 user user 0 2009-12-10 06:45 mypipe|
You could acomplish almost the same thing by using a regular file instead of a pipe with one very important exception. With named pipes, it doesn't matter in which order you fill or empty the pipe. i.e. you could have typed the cat < mypipe before you typed the ls > mypipe. With a regular file, if you type cat < myfile before the file exists, you get back.
-bash: myfile: No such file or directory
In other words, it doesn't block, waiting for data like a pipe does. Also, the text in a file stays put while the pipe "empties out"
![]() |
This site best viewed with a browser |
| Warning: This is a Debian centric site | |
| Many thanks to Debra and Ian Murdock for making Debian possible | |
| First created Apr 22, 2008 ~ Last revised December 10, 2009 |