We use Apache/mod_perl 2 and from time to time obtain a child httpd procedure that spins unmanageable, either consuming ever-growing levels of memory or max cpu.

I must monitor for such children every second approximately, so when finding one, send it a USR2 signal therefore it can dump its current Perl stack to the error logs.

(Observe that we're using rlimit/BSD::Resource, however when a procedure surpasses its memory rlimit, it dies immediately without any great way to log or do something (see Getting stack trace from Perl "Out of memory" error). So AFAICT rlimit must be accompanied by an exterior monitoring program.)

I observe that monit is extremely regarded as, however i can't determine in whatever way to watch and send an indication for an individual httpd process. It appears targeted towards killing or restarting services like apache in general. Am I missing something?

If I must write a Perl script that performs this, can there be something that will effectively monitor the procedure table? Proc::ProcessTable takes .02 secs of cpu to develop a single table, so running that each second appears unnecessarily costly. Opening a "/usr/bin/top -b -d 1 " and parsing the outcomes is my current best idea.

Clearly prefer to not badly reinvent one of the wheels if at all possible.

Thanks!

You should use control groups to rapidly get a listing of processes connected with apache, and direct your attention there. To put it simply the primary apache process right into a control group just before it breeding any child processes (eg, you might have a launcher process add itself to some control group), then read from the tasks file within the cgroup virtual directory. For every PID there, examine its CPU usage through the normal /proc systems.