On Fri, May 04, 2012 at 09:02:27PM +0200, John Kearney wrote: > set -m > cnt=0 > trap ': $(( --cnt ))' SIGCHLD > set -- {0..20} > while [ $# -gt 0 ]; do > if [[ ${cnt} -lt 10 ]] ; then > > ( > d=$(( RANDOM % 10 )) > echo $n sleeping $d > sleep $d > ) & > : $(( ++cnt )) > shift > fi > echo going to wait > sleep 1 > done
You're busy-looping with a 1-second sleep instead of using wait and the signal handler, which was the whole purpose of the previous example (and of the set -m that you kept in yours). And $n should probably be $1 there.