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
|