SUMMARY: ksh: How to tell when a job run in the background has completed?

From: <egold_at_fsa.com>
Date: Tue Mar 22 2005 - 11:20:27 EST
I want to thank everyone for all the help.
I must have gotten 20 responses in 1 hour.
The answer was to run the job in the background and then capture the value
of $!  which will contain the PID of the background job.
I will then save the PIDs in a file, array or directory to count the number
of jobs running in the background. I will check if the PIDs are still
running thru each loop and if any are done, i will remove them from the
list and count how many are still in the list. This will give me control
over the background jobs.

other people suggested using the "wait PID" command or "ptree". But the $!
seems to be the best for me.

thanks again!

=================

ORIGINAL MESSAGE:

Hi Gurus,
sorry if this is off topic.

in ksh, Is there any way to tell when each job run in the background have
completed if you are running 9 jobs at a time in the background?


I am writing 3 ksh scripts to run about 300 jobs but im stuck on one part
of the code.

basically i have the 3 main scripts which each readsits own list of
commands to run from a command_list file.
because of license issues I can only run 9 jobs at a time, so i am trying
to always have 9 jobs running at a time, no less or more than 9. If i run
more than 9 the jobs fails and moves on to the next one which will keep
failing until a license is available, and i only have 9 licenses.

The jobs all take different amount of times to complete.
I was trying to setup a loop to run the commands in the background and
count each job as it starts and finishes, but i realised i cant tell when
they finish if i run them in the background.

Is there any way to tell when jobs run in the background have completed?
That would solve my issue.

Here is the code I have so far, this is a sample of one the main jobs, i
have 3 sets of this main job and all 3 main jobs together cannot run more
than 9 jobs total at a time. If all 3 are running at the same time i would
like them to each run 3 at a time, but if 2 of the main jobs finish, i
would like the remaining one to start running 9 at a time so they each will
finish as fast as possible.


RUNREPORTS1 ()
{
OLDIFS=$IFS
IFS="
"
REPORTFILE=`cat /tmp/report_list`
for X in $REPORTFILE
do
ksh ". /etc/profile; $X &"
# This is the part of the code where I need help figuring out when a job in
the background is done, so i can count the # im running.
done
IFS=$OLDIFS
}


Here is a sample of the report_list1 file:

/data/bin/reporter -m MYCO -D $DATE -c"YTD:SDSL" -s 01/01/1997
/data/bin/reporter -m MYCO902 -D $DATE -c"YTD:JFDKL" -s 01/01/1997
/data/bin/reporter -m MYCO3 -D $DATE -c"YTD:WEL" -s 01/01/1997
/data/bin/reporternew -m MYCO884 -D $DATE -c"YTD:JYUKL" -s 01/01/1997
/data/bin/reporternew -m MYCO5 -D $DATE -c"YTD:JDFKL" -s 01/01/1997
/data/bin/reporterX -m MYCO6 -D $DATE -c"YTD:JZXKL" -s 01/01/1997
/data/bin/reporterX -m MYCO234 -D $DATE -c"YTD:JBVKL" -s 01/01/1997
/data/bin/reporternew -m MYCO8 -D $DATE -c"YTD:JKXCL" -s 01/01/1997
/data/bin/reporter -m MYCO65 -D $DATE -c"YTD:JKLKL" -s 01/01/1997
/data/bin/reporter -m MYCO234 -D $DATE -c"YTD:JOOKL" -s 01/01/1997
.
.
.
.
this goes on for over 300 unique commands



thank you in advance!




____________________________________
This e-mail message is for the sole use of the intended recipient(s) and
may contain proprietary, confidential and/or privileged information. Any
unauthorized review, use, disclosure or distribution is prohibited.  If you
are not the intended recipient (or an employee or agent responsible to
deliver it to the intended recipient), you may not copy or deliver this
message to anyone. In such case, you should destroy this message and kindly
notify the sender by reply e-mail.
_______________________________________________
sunmanagers mailing list
sunmanagers@sunmanagers.org
http://www.sunmanagers.org/mailman/listinfo/sunmanagers
Received on Tue Mar 22 11:20:55 2005

This archive was generated by hypermail 2.1.8 : Thu Mar 03 2016 - 06:43:45 EST