P
pgodfrin
Greetings,
I would like to create a 'driver' (simulation) program that calls
existing perl programs, waits for them to complete and provides some
feedback. Ideally I would like to have the driver echo to the screen
that the simulation is still running and perhaps provide some
information. That may be too ambitious, but that is the basic idea.
I have a handful of perl programs that do things - read a database
(kudos to the DBI modules) and output a report, from a few lines to a
few thousand.
Question #1: What is the proper way to execute the perl programs?
I am familiar with exec() and system() and have done this:
system("sallmr1 -n50000 >/dev/null");
system("srngmr1 -sr -es -n10000 >/dev/null");
system("srngmr2 -sr -es -n10000 >/dev/null");
Which executes these three programs sequentially - or by adding '&' at
the end I can execute them at the same time. Of course the 'calling'
program cannot wait for the background tasks because of the shell
return.
Which leads me down the path of fork(). If I were to code the
following:
for(1..2)
{
if($pid=fork)
{
# parent
} elsif (defined $pid)
{
# child
exec("sallmr1 -n50000 >/dev/null");
} # end child (elsif)
} # end for loop
do { $x=wait; print "$x died\n";} until $x==-1;
Then I would get a pair of runs, and wait until each child dies.
Question #2: Is there a way to echo to the screen that the wait() is
happening and provide some indication of progress?
To clarify this question, I had originally tried:
do {$x=wait; print ".";} until $x==-1;
Thinking I would get a period printed during the loop. (silly me -
wait only comes back when a child process dies...).
Of course if this is much to complicated a way to so a simulated load,
then so be it - just a plain old fork and wait works fine... And I
could always remove the /dev/null and actually see the called programs
output, which will tell me that it's still running... But I was
curious if there is a more elegant or at least interesting way of
doing this?
thanks,
phil
I would like to create a 'driver' (simulation) program that calls
existing perl programs, waits for them to complete and provides some
feedback. Ideally I would like to have the driver echo to the screen
that the simulation is still running and perhaps provide some
information. That may be too ambitious, but that is the basic idea.
I have a handful of perl programs that do things - read a database
(kudos to the DBI modules) and output a report, from a few lines to a
few thousand.
Question #1: What is the proper way to execute the perl programs?
I am familiar with exec() and system() and have done this:
system("sallmr1 -n50000 >/dev/null");
system("srngmr1 -sr -es -n10000 >/dev/null");
system("srngmr2 -sr -es -n10000 >/dev/null");
Which executes these three programs sequentially - or by adding '&' at
the end I can execute them at the same time. Of course the 'calling'
program cannot wait for the background tasks because of the shell
return.
Which leads me down the path of fork(). If I were to code the
following:
for(1..2)
{
if($pid=fork)
{
# parent
} elsif (defined $pid)
{
# child
exec("sallmr1 -n50000 >/dev/null");
} # end child (elsif)
} # end for loop
do { $x=wait; print "$x died\n";} until $x==-1;
Then I would get a pair of runs, and wait until each child dies.
Question #2: Is there a way to echo to the screen that the wait() is
happening and provide some indication of progress?
To clarify this question, I had originally tried:
do {$x=wait; print ".";} until $x==-1;
Thinking I would get a period printed during the loop. (silly me -
wait only comes back when a child process dies...).
Of course if this is much to complicated a way to so a simulated load,
then so be it - just a plain old fork and wait works fine... And I
could always remove the /dev/null and actually see the called programs
output, which will tell me that it's still running... But I was
curious if there is a more elegant or at least interesting way of
doing this?
thanks,
phil