LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   pipe, FIFO (https://www.linuxquestions.org/questions/linux-software-2/pipe-fifo-4175416480/)

qrange 07-13-2012 04:48 AM

pipe, FIFO
 
I need to 'split' output of a process to two identical FIFO pipes, so that two processes can read same output.
can you please tell me how to do it?

thanks.

dru8274 07-13-2012 11:23 AM

I think "tee" may help you to split the output into two fifos. At least, that's what the commands below do. But having experimented a bit, both fifo1 and fifo2 will remain "blocked", until they have both been connected to an output process.

"Tee" normally expects a filename as its argument. But here, a process substitution is used to redirect that output into fifo1 instead.

The commands below create two fifos, direct some data into them, and then connect each fifos to its own output process...
Code:

mkfifo fifo1
mkfifo fifo2
echo -e "one \ntwo \nthree \nfour " | tee >(cat - >fifo1) >fifo2 &

head -n2 <fifo1  >test1 &
tail -n2 <fifo2  >test2 &

And on checking the results, it seems to work okay...
Code:

$ cat test1
one
two
$ cat test2
three
four

Happy with ur solution... then tick "yes" and mark as Solved!

qrange 07-13-2012 04:31 PM

thanks, but I've been trying tee for hours with no success. I'm using video streams, and two vlc players at 'end' of pipes. but it seems that only one pipe can work, not two at same time. maybe the problem is in very small buffer of fifo. so it breaks when one pipe is 'faster'.

dru8274 07-13-2012 07:13 PM

Quote:

Originally Posted by qrange (Post 4727436)
...but it seems that only one pipe can work, not two at same time. maybe the problem is in very small buffer of fifo. so it breaks when one pipe is 'faster'.

From what I have read, you might be right. The pipe's internal-buffer has a size limit, which is stored in /proc/sys/fs/pipe-max-size.

I haven't tried it myself, but this post here suggests howto resize the pipe buffer.

sundialsvcs 07-16-2012 10:08 AM

It seems likely to me that video streaming data would exceed the design capacity of a pipe. What I would expect to be used in this case is a shared-memory buffer of some kind. (And I would fully expect such a thing to already exist, so look before you write.)


All times are GMT -5. The time now is 04:10 AM.