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

It's been a while since I did this sort of thing, but IIRC you can't reliably catch the fact that the user hit STOP on the browser, so it is most likely that your forked progs will continue running until they complete.

Michael

  • Comment on Re: browser cancels request-> forked procs die?

Replies are listed 'Best First'.
Re: Re: browser cancels request-> forked procs die?
by jorg (Friar) on Nov 26, 2003 at 21:29 UTC
    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
      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