On Thu, 14 Aug 2003, Niall Flinn wrote:
> Hi folks,
>
> I'm writing my first actual useful perl scripts and I've run into the following
> problem - I'm using the "system" function to run a command line process (a 3d
> renderer, as it happens) from within my script. This works fine, except that
> sometimes the process hangs and leaves my perl script waiting for a return that
> never comes. How can I make my script carry on and try running the process again?
> I'm guessing that I need to use the "alarm" function, but as a newbie, the example
> shown in the perl docs doesn't make much sense to me :(
>
> Cheers,
>
> Niall
Here's how I'm doing the same this..
while ($line = <TESTFILE>)
{
# $start=time;
my $full_line;
chomp($line);
#$full_line = join("/",$test_path,$line,$cmd);
if ($test_path)
{
$full_line = "$test_path/$line/$cmd";
}
else
{
$full_line = "$line/$cmd";
}
print "Working on .... $full_line\n";
eval
{
local $SIG{ALRM} = sub { die "alarm\n" }; # NB: \n
required
alarm $timeout;
my $start = time;
print LOGFILE
"*****************************************************************************";
print LOGFILE "\n$line";
system("$mpi_run $full_line >> logfile.$today");
my $end = time;
my $totaltime = $end - $start;
print LOGFILE "\nTime for test: $totaltime
sec's\n";
alarm 0;
};
if ($@)
{
die unless $@ eq "alarm\n"; # propagate
unexpected errors
# timed out
print LOGFILE "\n!!!! $full_line TIMED OUT
!!!!\n";
print "\n$full_line timed out\nKilling job that
timed out\n";
`$killname $killsig mpirun`;
#sleep 2;
# kill off jobs on the remote hosts
my $i;
for ($i=0; $i <=$#kill_num; $i++)
{
`rsh $kill_num[$i] $killname
$killsig $cmd`;
}
next;
}
else
{
# job didn't time out
}
}
Sorry for the bad formatting..
HTH
Denis
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]