Sorry it's a long script so I was trying to give the portion of code that is the problem. This is the subprocedure:
sub processCnfDirectory { use Time::HiRes(gettimeofday); use File::Basename; my($path) = @_; my $pid; local $SIG{ALRM} = sub { $didTimeout=1; print OUTPUT "timeout"; print "process id", $pid, "\n"; kill 9, $pid; die "Timeout\n"; }; print( "working in: $path\n" ); # append a trailing / if it's not there $path .= '/' if($path !~ /\/$/); # loop through the files contained in the directory for my $file (glob($path . '*')) { # check if the file is a directory if( -d $file) # pass the directory to the routine ( recursion ) processCnfDirectory($file); } elsif ($file =~ /.*\.cnf/) { print OUTPUT basename($file), ","; # run using the first solver $pid = fork; eval { $didTimeout=0; $start1=gettimeofday(); alarm $timeout; #$pid = `$solver1 $file`; $result = `$solver1 $file`; waitpid($pid, 0); }; alarm 0; $end1=gettimeofday(); if($didTimeout == 0) { print OUTPUT $end1 - $start1; } print OUTPUT ","; # run using the second solver $pid = fork; eval { $didTimeout=0; $start2=gettimeofday(); alarm $timeout; #$pid = `$solver2 $file`; $result = `$solver2 $file`; waitpid($pid, 0); }; }; alarm 0; $end2=gettimeofday(); if($didTimeout == 0) { print OUTPUT $end2 - $start2; } print OUTPUT "\n"; } } }
So what it does is it reads in a directory on the command line. It loops through the directory recursively to include subdirectories. Inside a directory it runs a solver on each file. Then it records the amount of time it took to run. The solvers are also command line input.

In reply to Re^2: Timeout and kill by nelson64
in thread Timeout and kill by nelson64

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.