help-bash
[Top][All Lists]
Advanced

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

Re: [Help-bash] What the process started by <() may not be a child?


From: Greg Wooledge
Subject: Re: [Help-bash] What the process started by <() may not be a child?
Date: Thu, 15 Nov 2018 10:10:37 -0500
User-agent: NeoMutt/20170113 (1.7.2)

On Thu, Nov 15, 2018 at 09:04:14AM -0600, Peng Yu wrote:
> I don't understand the difference between the two <(). Why the first
> one is not a child but the second one is a child?

> echo <(echo 1:$BASHPID>&2) <(echo 2:$BASHPID>&2)
> echo "$!"

They're both background child processes.  The problem is that there is
only one $! parameter available, and it can only hold one PID at at time.

> If I do want to wait for both to be finished, is there a
> way to do so in bash? Thanks.

At some point you have to give up on the sugary syntactic additions
and just write some actual code.  In this case, acknowledge that <() is
syntactic sugar for setting up your own named pipe and background
process, and that you might have exceeded its usefulness.

fifo=something
trap 'rm -f "$fifo"' EXIT
mkfifo "$fifo" || exit
writer process 1 > "$fifo" & pid1=$!
cat "$fifo" <(writer process 2)
pid2=$!
wait "$pid1" "$pid2"



reply via email to

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