Re: bash - pipe



In message <48dc9029$0$1075$4fafbaef@xxxxxxxxxxxxxxxxxxx>, Antonio Macchi
wrote:

hi

I can't understand this pipe-behavior..

------------------

$ mkfifo fifo

$ echo 123 > fifo &
[1] 7535

$ echo 456 > fifo &
[2] 7536

$ read -n3 < fifo
[1]- Done echo 123 >fifo
[2]+ Done echo 456 >fifo

$ read -n3 < fifo

(hang! - empty pipe)


--------------------


More than one process can append his output to a pipe

but...

Only one process can read a pipe
When he has fished, no more processes can read remaining-data

This certainly works:

ldo@theon:~> mkfifo /tmp/fifo
ldo@theon:~> echo 123 >/tmp/fifo &
[1] 25790
ldo@theon:~> echo 456 >/tmp/fifo &
[2] 25791
ldo@theon:~> cat </tmp/fifo
456
123
[1]- Done echo 123 > /tmp/fifo
[2]+ Done echo 456 > /tmp/fifo

Trying to reproduce your example:

ldo@theon:~> echo 123 >/tmp/fifo & echo 456 >/tmp/fifo &
[1] 25800
[2] 25801
ldo@theon:~> read -n3 </tmp/fifo; echo $REPLY
123
bash: echo: write error: Broken pipe
ldo@theon:~>
[1]- Done echo 123 > /tmp/fifo
[2]+ Exit 1 echo 456 > /tmp/fifo

The second echo died as soon as the input end of the pipe was closed.
.



Relevant Pages

  • Re: Redirect an Pipe
    ... in die Pipe eines Hintergrundprozesses schreiben. ... in einem Block zu fassen? ... | mkfifo FIFO ...
    (de.comp.os.unix.shell)
  • Re: Redirect an Pipe
    ... Nikolaus Rath writes: ... in die Pipe eines Hintergrundprozesses schreiben. ... | mkfifo FIFO ... Wenn Sie mir E-Mail schreiben, stellen | When writing me e-mail, please ...
    (de.comp.os.unix.shell)
  • Re: fork process to handle fifo input
    ... >> work on the input of the named pipe. ... >> process in order to collect to child processes before quiting. ... >> collect data from syslog through the fifo as they should. ...
    (comp.lang.perl.misc)
  • bash - pipe
    ... $ read -n3 < fifo ... More than one process can append his output to a pipe ...
    (alt.os.linux)
  • how to tell FIFO (named stream pipe) size
    ... How can I tell what size a FIFO is? ... I am under these impressions: ... the pipe, then the write is guaranteed to be atomic, thus the byte ... service reads from many child processes, ...
    (comp.unix.programmer)