Hi Cyrille,
Thanks for the examples. If the "jobs" command will not work the way it used
to then this looks a good way to go. But sigchld is, for me, a more elegant
solution.

Regards

Pete

2009/12/24 Cyrille Lefevre <[email protected]>

>
> Peter Hitchman a écrit :
>
>
>  Is there a better way to check the exist status from a bunch of background
>> jobs in a script?
>>
>
> never used sigchild, but my answer would be to put them in an variable
> or array and to wait for every process in turn :
>
> pids=
> sleep 60 &
> pids="$pids $!"
> sleep 60 &
> pids="$pids $!"
>
> for pid in $pids; do
>        wait $!
>        rc=$?
> done
>
> alternative :
>
> npids=0
> sleep 60 &
> pids[npids++]=$!
> sleep 50 &
> pids[npids++]=$!
>
> while :; do
>        for (pidn = 0; pidn < npids; pidn++); do
>                if ! kill -0 ${pids[pidn]}; then
>                        wait ${pids[pidn]}
>                        rc=$?
>                        unset pids[pidn]
>                fi
>        done
>        (( ! ${#pids[*]} )) && break
>        sleep 10 # let's the cpu do something else
> done
>
> this solution also permit to handle a timeout if necessary.
>
> PS : noth solutions not tested but should work.
>
> Regards,
>
> Cyrille Lefevre
> --
> mailto:[email protected]
>
>
>
_______________________________________________
ast-users mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-users

Reply via email to