CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Need a Custom or Prewritten Perl Program?: I need a program that...:
Kill system process after timeout

 



Aminxp20
New User

Dec 8, 2014, 2:08 AM

Post #1 of 1 (31744 views)
Kill system process after timeout Can't Post

Hi
I need a perl code that runs a Dos program with a timeout and kills the program if the timeout is reached. For the timeout part, I was able to find this code (and it works too). But this doesn't kill the Dos program after timeout is reached:


Code
my ($XfoilLocation, $ResultsDirectory, $basename, $timeout) = @ARGV; 

my $stringA = $XfoilLocation . ' <' . $ResultsDirectory . '\\' . $basename . '.xfoil >nul';

eval {
local $SIG{ALRM} = sub { die "alarm\n" }; # NB: \n required
alarm $timeout;
system($stringA);
alarm 0;
};
if ($@) {
die unless $@ eq "alarm\n"; # propagate unexpected errors
# timed out
}
else {
# didn't
}


For killing the Dos program based on its PID, I found this piece of code:


Code
my $cpid; # Run Xfoil and get the PID of this instance of Xfoil 
{
defined($cpid = fork) or die $!;
$cpid and last;
exec($stringA);
}
echo $cpid


Now, can someone please help me in combining the two? Because just pasting the second code into the first one doesn't work.

For killing a process via its PID I can use:

Code
my $stringC = 'taskkill /f /pid ' . $cpid; 
system($stringC);


Any help is highly appreciated.


(This post was edited by Aminxp20 on Dec 8, 2014, 2:13 AM)

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives