Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

My apache2 is using running slowly. A single PHP file is takes long time to process. The server is live. I dont want to restart it. So I thought I attach strace to it and check whats happening.

So I run

strace -p `cat /var/run/apache2.pid `

After that I load some testing urls. Load then many times. But I didn't see any output at the strace console!

Then I remember there are many child processes. So I checked them

$ ps ax | grep apache[2] -i
 1877 ?        Ss     0:02 /usr/sbin/apache2 -k start
 2006 ?        S      0:00 /usr/sbin/apache2 -k start
 2007 ?        S      0:00 /usr/sbin/apache2 -k start
 2008 ?        S      0:00 /usr/sbin/apache2 -k start
 2009 ?        S      0:00 /usr/sbin/apache2 -k start
 2010 ?        S      0:00 /usr/sbin/apache2 -k start
 9985 ?        S      0:00 /usr/sbin/apache2 -k start
 9988 ?        S      0:00 /usr/sbin/apache2 -k start
 9997 ?        S      0:00 /usr/sbin/apache2 -k start
 9998 ?        S      0:00 /usr/sbin/apache2 -k start
 9999 ?        S      0:00 /usr/sbin/apache2 -k start

Now my question is how do I strace all of these child processes? How do I know which child process is handling the request right now?

share|improve this question
    
Did anyone even see this question? –  Shiplu Feb 21 '12 at 22:02
add comment

1 Answer

up vote 1 down vote accepted

The short answer: you cannot predict which apache process will handle a request.

The simplest way to solve this problem is to dedicate an xterm to every apache process and run strace -p <pid> in it for each apache pid.

When I'm in this situation, I usually do this in my httpd.conf (on a development box):

<IfModule prefork.c>
StartServers       1  <--------
MinSpareServers    1  <--------
#StartServers       8
#MinSpareServers    5
MaxSpareServers   20
ServerLimit      256
MaxClients       256
MaxRequestsPerChild  4000
</IfModule>

This reduces the number of processes I need to monitor... obviously it's not a good solution for a production environment.

FYI, if you need to strace a process that will fork after you start stracing (for instance, a wsgi process) you can use strace -fp <pid_of_future_forker> and it will strace the forked children automagically.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.