1

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?

1
  • Did anyone even see this question? Feb 21, 2012 at 22:02

1 Answer 1

1

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.

1
  • can we just attach strace too all apache process?
    – slier
    Jan 21, 2015 at 7:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .