A named pipe is a special kind of file that you can use to connect two unrelated processes together without having to specifically set up a pipeline from the shell.
You make a named pipe file with the "mknod" command as follows: "mknod /path/to/pipe p". The trailing "p" indicates that you're making a named pipe. (The mknod command has other uses, such as making device nodes.)
Two programs can communicate in a single direction via the named pipe as follows: One program opens the pipe for reading, and the other opens it for
writing. Once this happens, the named pipe works pretty much like the unnamed variety set up by the shell.
You can experiment with this in the shell. For example:
$ mknod foo p
$ cat foo > bar
$ ls -l > foo
What this will do is make a named pipe named "foo", and attach "cat" to it as a reader. The shell redirects cat's output to the file "bar." The subsequent ls command gets redirected to the pipe "foo" by the shell. It becomes the writer, with its output forwarded to the "cat" command. When the ls process completes, the pipe closes and "cat" gets an end-of-file indication. This causes cat to close "foo", and in this example, it terminates at that point. If you look in the file "bar", you'll see the output of ls.
You can get fancier with this:
$ mknod george p
$ mknod paul p
$ mknod john p
$ mknod ringo p
$ cat george paul john ringo > output &
$ command1 > george &
$ command2 > paul &
$ command3 > john &
$ command4 > ringo &
Tada: You've concatenated the output of four separate programs via named
pipes. It's not terribly interesting in this specific use--there are more concise ways to concatenate the output of four unrelated commands. Named pipes are most interesting when the writer and the reader are trying to collaborate over a longer "distance," such as between two separate shell sessions, or separate screen windows as the case may be.
I hope this helps,
We sell Spatulas, and that's all!http://spatula-city.org/~im14u2c/http://sdk-1600.spatula-city.org/http://intyos.spatula-city.org/
From: Alan Young <address@hidden>
To: Michael Schroeder <address@hidden>
Sent: Thursday, February 8, 2007 10:31:24 AM
Subject: Re: File descriptors and screen and you
Michael Schroeder wrote:
>> I want to avoid going the tmp file route if at all possible. Is there a
>> way I can echo tty's output so that I can grab it from a filehandle?
> You need some interprocess communication way. Some ways could be
> - a named pipe (but that's close to a tmp file)
I'm not as familiar with the shell as a I should be. How would I go
about using a named pipe? And what's the differences between that and a
It's been suggested that if I want to make this really portable then a
tmp file is actually the best way to go, so it's not off the list, just
> - some code using sockets (complicated)
and more trouble than its worth.
Thanks for the input and help.
screen-users mailing list