in reply to Re: browser cancels request-> forked procs die?
in thread browser cancels request-> forked procs die?

ok point taken. So what can I do to prevent that these processes will run forever? There is an odd case that the programs i'm calling go into an endless loop. Can i do a timeout of some sort, and then kill the process off?


Jorg

"Do or do not, there is no try" -- Yoda
  • Comment on Re: Re: browser cancels request-> forked procs die?

Replies are listed 'Best First'.
Re: Re: Re: browser cancels request-> forked procs die?
by mpeppler (Vicar) on Nov 26, 2003 at 22:07 UTC
    It's a little hard to say off-hand as I don't know what your subprocess does. If you have control over the subprocesses source then you could put an alarm in its code and terminate it if it runs for more than X seconds. Or you could do the same thing in the parent (your CGI/modperl handler) where you could do something like (pseudo code):
    $SIG{ALRM} = sub { die 'Timeout'; }; alarm( some decent duration ); eval { fork the child here wait for the child (waitpid() or similar) if the child returns reset the alarm (alarm(0)) }; if($@) { if($@ =~ /Timeout/) { # child exceeded authorized run time, so kill it kill(15, $child); } else { handle other fatal problems.... } }
    It's up to you to determine what amount of time your child process should normally run, so that you don't interrupt a normally executing process.

    Michael