if [ $# -lt 1 ] then echo "usage: getyourfilehost2.sh [url1] [url2] .... " exit -1 fi
for URL in $@ do cont_flg=1 kill -USR2 $PROCESSID while [ $cont_flg -eq 1 ] do if [ $MAXCOUNT -gt 0 ] then wgeturl $URL & cont_flg=0 else echo "Too match ...." >&2 sleep 10 fi done done
function spawn_dl {
# $targets and $RANDOM should be refered in parent process.
local url=$targets[1]; shift targets
waiturl $[$max_sleep * ($RANDOM / 32768.0)] $url &
}
function waiturl {
integer sec=$1
echo invoking $2
# このサンプルでは、乱数秒待つタスクを download の代わりに用いる
sleep $sec
echo $2 by $$ after $sec
}
function TRAPCHLD {
echo -n in TRAPCHLD ' '
if (($#targets)); then
spawn_dl
else
echo ... No more targets.
fi
}
while (($#targets)); do
spawn_dl
# When number of jobs exceeds MAXCOUNT
if ((${(%):-%j} >= $MAXCOUNT)); then
wait
fi
done