coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: `tee` get stuck with dependency.


From: Pádraig Brady
Subject: Re: `tee` get stuck with dependency.
Date: Thu, 17 Nov 2016 17:48:55 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0

On 17/11/16 17:12, Jin Li wrote:
> Hi all,
> 
> I have the following test case.
> 
> ~~~
> tmpdir=$(mktemp -d)
> cd "$tmpdir"
> mkfifo a b
> seq 10 | tee a b > /dev/null &
> pid=$!
> set -v
> x=$(wc -l a)
> sed -e "s/^/b$x/" b
> wait "$pid"
> ~~~
> 
> In the above test case, the second fifo `b` will depend on the first
> fifo `a`. But it will get stuck in reading the first fifo `a`, in the
> following line,
> ~~~
> x=$(wc -l a)
> ~~~
> 
> Do you have some idea to resolve `tee` with dependency for two fifos?
> Many thanks for your help.

tee(1) is blocked on the open("b"), and so not writing to a.
Generally one couldn't process _all of_ 'a' (with wc) and only then 'b',
because if there was a lot of data on the input,
what would tee do with it if b wasn't being read?

I.E. you'll need to sink all the data to somewhere,
if you want to subsequently process it depending on the record count.
The standard way is to sink to file first.

tee(1) would still be useful in this case to avoid processing the file twice:

  trap 'rm b' EXIT
  x=$(seq 10 | tee b > >(wc -l))
  sed -e "s/^/b$x/" b

Pádraig



reply via email to

[Prev in Thread] Current Thread [Next in Thread]