Results 1 to 1 of 1
Hi All,
I have the following kshell script. The run_job function uses a locking mechanism to ensure that when a new job is started is more than three jobs are ...
- 06-24-2010 #1Just Joined!
- Join Date
- Nov 2004
- Posts
- 3
CPU intensive background jobs
Hi All,
I have the following kshell script. The run_job function uses a locking mechanism to ensure that when a new job is started is more than three jobs are running it will sleep till one of them is free. The idea here is to kick off 120 jobs. Three of them will run and the remaining will sleep and poll. As soon as one of the three finished a lock is released and another jobs aquires the key and continues. Note that each job requires substantial CPU and memory.
when I run this program once a certain number of jobs (~41) have been started the main script seems to get stuck. The log file only has output from the child jobs and once all the child jobs have completed the main script never starts of any more jobs and is stuck and is not using CPU. Is there a limit of the number of children a process can spawn? Also in Linux the quantum a process gets divided by 2 when a child process is created. Might this have anything to do with that?
Code:run_job() { typeset key typeset cmd typeset rc echo "Starting $0 stats for $1" key=`lockorwait -s -i 300 -c 3 compute.lock` echo "acquired $key" cmd="compute.ksh -d $1 -o $OUTPUT" echo $cmd eval $cmd rc=$? echo "releasing $key" unlock -s $key return $rc } run_job set -A JOBS jobs=120 while [[ $JobCount -lt $days ]]; do echo "run_job $JobCount >> $LOG_FILE 2>&1 &" run_job $JobCount >> $LOG_FILE 2>&1 & let JOBS[JobCount]=$! sleep 2 echo "Started Job # $JobCount (PID:${JOBS[${JobCount}]})" let JobCount=JobCount+1 done rc=0 while [ $JobCount -gt 0 ]; do echo "waiting for job completion; (${JobCount} job(s) in queue)" let JobCount=JobCount-1 wait ${JOBS[$JobCount]} if [ $? -ne 0 ]; then rc=1; fi done


Reply With Quote