Am 04.05.2012 21:11, schrieb Greg Wooledge: > 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. > see my response to mike.
what you are thinking about is either what I suggested or something like this function TestProcess_22 { local d=$(( RANDOM % 10 )) echo $1 sleeping $d sleep $d echo $1 exiting $d } function trap_SIGCHLD { echo "SIGCHLD"; if [ $cnt -gt 0 ]; then : $(( --cnt )) TestProcess_22 $cnt & fi } set -m cnt=20 maxJobCnt=10 trap 'trap_SIGCHLD' SIGCHLD for (( x=0; x<maxJobCnt ; x++ )); do : $(( --cnt )) TestProcess_22 $cnt & done wait trap - SIGCHLD