Skip to content

Instantly share code, notes, and snippets.

@shaunhess
Created March 13, 2014 01:00
Show Gist options
  • Select an option

  • Save shaunhess/9519968 to your computer and use it in GitHub Desktop.

Select an option

Save shaunhess/9519968 to your computer and use it in GitHub Desktop.
################################################################################
# Making custom named pipes
################################################################################
Open two ssh sessions to a system. In one, create your pipe and then send some command output to it.
$ mkfifo mypipe
$ cal > mypipe
Don’t worry that your command just seems to hang.
In the other, read from the pipe.
$ cat < mypipe
September 2013
Su Mo Tu We Th Fr Sa
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
What should pop out of this simple demonstration is how your pipe is able to allow processes running in separate sessions to communicate. Depending on permissions, separate processes run by separate users are just as easy. And, of course, these pipes are reusable. They’ll still be sitting in your file system after your commands have completed.
You can also write scripts or run commands that wait for output from a named before taking the next step – as in this example. In one session, do this:
$ if read line <mypipe; then
> echo this is a test
> fi
Again, the session seems to freeze. But then send something through the pipe from the other session and you’ll be back at the prompt:
$ echo hello > mypipe
Check on your first window again and you should see something like this:
$ if read line <mypipe; then
> echo this is a test
> fi
this is a test
You can look for named pipes on your systems using a command such as this:
$ find / -type p -print 2> /dev/null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment