Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Waiting for a process without using pid



On Mon, Sep 20, 2010 at 7:55 AM, Bart Schaefer
<schaefer@xxxxxxxxxxxxxxxx> wrote:

> Perhaps I was trying to make my solution too general; i.e., I didn't
> want to care how many children were started or whether their PIDs had
> been remembered.  But if you always have exactly two children, why not
> this?
>
>    coproc read -E
>    trap "print -p" CHLD
>
>    ./child.sh &
>    pid1=$!
>    ./child.sh &
>    pid2=$!
>
>    read -p
>    kill $pid1 >&/dev/null
>    kill $pid2 >&/dev/null

You *can* rewrite that to not care how many children there are.

for thing in $stuff; do
    ./child.sh $thing
    set -A pids $pids $!
done

for child in $pids; do
    kill $child >&/dev/null
done



Messages sorted by: Reverse Date, Date, Thread, Author