Psg amount of running jobs?

Hey,

I have to run a lot of jobs (300) and would like to start at one time only 20 jobs and then after thos jobs are finished the next 20. But how to "ask" for whether the jobs are finished?

actually, my starting scripts looks like that:

for i in jal_*
do
        cd ./$i/
        outname="b_"$i".job"
        nohup ./$outname &
        cd ..
done

One jobs creates always vier "childs" and I thought of using psg with the name of the folder to pick only the jobs I startet. But how to ask for the amount of still running jobs with psg? Or is there another way of figuring this out?

Hope this wasn't too confused...

Thanks alot,
Ergy

Try something like

j=0
for i in jal_*
do
  nextjob=${i}/b_${i}.job
  [ -f "nextjob" ] || continue
  nohup "$nextjob" &
  if [ $((j+=1)) -gt 20 ]
  then
    wait
    j=0
  fi
done
wait