Find out what high CPU usage apache process is actually doing?

Solution 1:

Well, in case you're feeling brave:

gdb -p 20788

then issue bt to see the stack-frame, for e. g.

And BTW, there's also ltrace to mention — try it as well.

UPD.: well, ok, since now we have an idea that Apache is really running something, why wouldn't ya look at mod_status output — Extended one?

Solution 2:

An very easy approach is to use htop. You can sort for the high CPU processes and then use

  • s for strace a process
  • l for lsof to see the open files of a processes
  • L to ltrace.

I found that at least one of that options finds the script that generates the load and you can of course use this on a production web server to debug.

Solution 3:

You could try:

  • iotop (showing I/O on the system)
  • netstat -t (showing connections)
  • Take a look at the apache logfiles and find out what the server did last
  • set some RLimits for the apache process. When these limits are reached the process will be killed, giving you some more information