We use Apache/mod_perl 2 and occasionally get a child httpd process that spins out of control, either consuming ever-increasing amounts of memory or max cpu. Usually due to an infinite loop or other bug in a specific part of the site - this sort of thing happens.
I would like to monitor for such httpd children every second or so, and when finding one, send it a USR2 signal so it can dump its current Perl stack to our error logs. (Note that we are using rlimit/BSD::Resource, but when a process exceeds its memory rlimit, it dies immediately with no good way to log or take action (see Getting stack trace from Perl "Out of memory" error). So AFAICT rlimit will have to be complemented by an external monitoring program.) I see that monit is highly regarded, but I can't figure out any way to monitor and send a signal to an individual httpd process. It seems geared towards killing or restarting services like apache as a whole. Am I missing something? If I have to write a Perl script that does this, is there anything that will efficiently monitor the process table? Proc::ProcessTable takes .02 secs of cpu to generate a single table, so running that every second seems unnecessarily expensive. Opening up a "/usr/bin/top -b -d 1 |" and parsing the results is my current best idea. Obviously would rather not badly reinvent a wheel if possible. Thanks! Jon