Re: How do I end processes that time out?

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
J. Romano wrote:
Quoted text here. Click to load it

Your assumption seems correct to me. My suggestion is that if you want
to get fancy with IPC you should leave the backticks behind and do the
operations manually with fork and exec. That way when you fork you'll
get the PID of the kid and can kill it if there is an alarm. Here's a
rough (untested since I am at work) idea of what I am suggesting:
my $pid;
$SIG = 'IGNORE'; # avoid creating zombie processes

eval {
local $SIG = sub { die "alarm\n" }; # NB: \n required
alarm 3; # wait a maximum of three seconds

die "Can't fork: $!" unless defined($pid = open(CLD, "-|"));

if ($pid) {                        # parent
while (<CLD>) {
print; #or whatever
close CLD;
} else {                           # child
exec 'finger', 'some_user@somehost';

alarm 0;

if ($@) {
die unless $@ eq "alarm\n"; # propagate unexpected errors
# Timed out:
    print "Timed out!\n";
    kill 9, $pid;

Re: How do I end processes that time out?

FYI I tested this now and it seems to work properly

Site Timeline