Re: bash - pipe
- From: Lawrence D'Oliveiro <ldo@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 26 Sep 2008 21:25:05 +1200
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.
.
- Follow-Ups:
- Re: bash - pipe
- From: Antonio Macchi
- Re: bash - pipe
- References:
- bash - pipe
- From: Antonio Macchi
- bash - pipe
- Prev by Date: Re: bash - pipe
- Next by Date: Re: bash - pipe
- Previous by thread: Re: bash - pipe
- Next by thread: Re: bash - pipe
- Index(es):
Relevant Pages
|