I'm using PSEXEC to run remote process with system($CMD)
in perl.
I have a computer (lets call it-#1) that runs system cmd
, and another computer (lets call it-#2), which "receives" commands from computer #1.
Sometimes the process in the second computer (#2) gets stuck.
How can I set a timeout to the system cmd
in computer #1 that will force-terminate the cmd after several minutes?
thanks for the answers, but: i'm tring to do somthing very simple, I have 2 perl files. file#1 that counting seconds 1 to 10. (+print to the screen) file#2-Timeout file that cal file#1 (system command) that should terminate file #1 after 5 sec.
the results...: timeout occurred, but process #1 still running...
file#2
$timeout=5;
eval {
local $SIG{ALRM} = sub { die "alarm\n" }; # NB: \n required
alarm $timeout;
$nread = system('F:\perl1.pl');
alarm 0;
};
if ($@) {
die unless $@ eq "alarm\n"; # propagate unexpected errors
print "process terminated\n";}
else {
# didn't
}
file#1
$i=0;
while($
i<10){
sleep(1);
$i++;
print "$i\n";
}
CMD window results:
C:\>F:\perl2.pl
1
2
3
4
process terminated
C:\>5
6
7
8
9
10