[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Parallelism a la make -j <n> / GNU parallel
From: |
John Kearney |
Subject: |
Re: Parallelism a la make -j <n> / GNU parallel |
Date: |
Fri, 04 May 2012 21:41:49 +0200 |
User-agent: |
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20120428 Thunderbird/12.0.1 |
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
- Re: Parallelism a la make -j <n> / GNU parallel, (continued)
- Re: Parallelism a la make -j <n> / GNU parallel, Chet Ramey, 2012/05/04
- Re: Parallelism a la make -j <n> / GNU parallel, Mike Frysinger, 2012/05/04
- Re: Parallelism a la make -j <n> / GNU parallel, Andreas Schwab, 2012/05/04
- Re: Parallelism a la make -j <n> / GNU parallel, Mike Frysinger, 2012/05/04
- Re: Parallelism a la make -j <n> / GNU parallel, John Kearney, 2012/05/04
- Re: Parallelism a la make -j <n> / GNU parallel, Greg Wooledge, 2012/05/04
- Re: Parallelism a la make -j <n> / GNU parallel,
John Kearney <=
- Re: Parallelism a la make -j <n> / GNU parallel, Mike Frysinger, 2012/05/04
- Re: Parallelism a la make -j <n> / GNU parallel, John Kearney, 2012/05/04
- Re: Parallelism a la make -j <n> / GNU parallel, Mike Frysinger, 2012/05/05
- Re: Parallelism a la make -j <n> / GNU parallel, Andreas Schwab, 2012/05/05
- Re: Parallelism a la make -j <n> / GNU parallel, Chet Ramey, 2012/05/07
- Re: Parallelism a la make -j <n> / GNU parallel, John Kearney, 2012/05/05
- Re: Parallelism a la make -j <n> / GNU parallel, Mike Frysinger, 2012/05/06
- Re: Parallelism a la make -j <n> / GNU parallel, John Kearney, 2012/05/06
- Re: Parallelism a la make -j <n> / GNU parallel, Chet Ramey, 2012/05/04
- Re: Parallelism a la make -j <n> / GNU parallel, Mike Frysinger, 2012/05/05