[TriLUG] confessions of a bash junky: the mkfifo command
jonc at nc.rr.com
jonc at nc.rr.com
Tue Aug 28 11:14:38 EDT 2007
I write a lot of scripts. I mean a LOT of scripts. If I can solve a problem in 10 to 15 minutes by throwing it into a bash script, then that's what happens. So I *love* bash... unabashedly.
I recently ran across an old command 'mkfifo" and tilted my head as I wondered once more, what the heck this does... In earlier days I had stared at the man pages for mkfifo with blinking eyes and then moved on... thinking that perhaps one day I might be wise enough to comprehend this technical soup before me, but not that day... No my friend - not that day, but *this* day!
Below are my notes on using 'mkfifo'. Submitted for your diversion.
# You can use the mkfifo command to create an input/output pipe (or buffer)
# Feed info into the pipe using one process, pull info out of the pipe
# using another processes...
# Make the pipe:
# The pipe is created in the current directory and looks and acts like a file
# (doesn't everything in Unix?)
# Feed info into the pipe. In this case the output from the find command.
find /home/jonc >imapipe
# Note: the script stays frozen here till the pipe is cleared
# Another process runs and pulls from the pipe
# Note: this clears the buffer (or pipe) and the previous script now continues
# Note2: you can grab from the pipe first - which causes that script
# to wait for input. Then when the first script runs and loads the buffer
# the second script immediately pulls the data out and continues to process.
# So this can be used as a timer to co-ordinate scripts..
# to wait for input, or
# to wait for output
# from another script or process.
# Note3: Multiple processes can put information into the buffer - the info
# stacks up and comes out First In -> First Out
# When a process pulls from the buffer, it gets everything in the buffer
# and the other processes that loaded the buffer all continue.
# An interesting way to set off multiple scripts simultaneously
Jon "bash me" Carnes
More information about the TriLUG