4
votes

I wish to launch apache so it forks one child process. (I'm profiling a module. I know about the -X flag,)

according to the docs

Two directives set hard limits on the number of active child processes and the number of server threads in a child process, and can only be changed by fully stopping the server and then starting it again. ServerLimit is a hard limit on the number of active child processes, and must be greater than or equal to the MaxClients directive divided by the ThreadsPerChild directive. ThreadLimit is a hard limit of the number of server threads, and must be greater than or equal to the ThreadsPerChild directive. If non-default values are specified for these directives, they should appear before other worker directives.

I tried setting my settings to:

<IfModule prefork.c>
StartServers       1
MinSpareServers    1
MaxSpareServers    1
ServerLimit      1
MaxClients       1
MaxRequestsPerChild  4000
</IfModule>


<IfModule worker.c>
StartServers         1
MaxClients          25
MinSpareThreads     25
MaxSpareThreads     25 
ThreadsPerChild     25
MaxRequestsPerChild  0
</IfModule>

When I restart, I still get four processes.

root     17173     1  0 11:44 ?        00:00:00 /usr/sbin/httpd -k start
root     17205 17173  0 11:46 ?        00:00:00 /usr/sbin/httpd -k start
apache   17206 17173  0 11:46 ?        00:00:00 /usr/sbin/httpd -k start
apache   17207 17173  0 11:46 ?        00:00:00 /usr/sbin/httpd -k start

What am I doing wrong?

Oddly, if I use the -X flag, I still get three processes.

/usr/sbin/httpd -X -f /etc/httpd/conf/httpd.conf

apache   17224  4097  1 11:51 pts/1    00:00:00 /usr/sbin/httpd -X -f /etc/httpd/conf/httpd.conf
root     17226 17224  0 11:51 pts/1    00:00:00 /usr/sbin/httpd -X -f /etc/httpd/conf/httpd.conf
apache   17227 17224  0 11:51 pts/1    00:00:00 /usr/sbin/httpd -X -f /etc/httpd/conf/httpd.conf
1

1 Answers

3
votes

You should get two process, the first one is owned by root, binds the 80 port, manage child[ren], the second is the one answering the http request.

Try with ps auxf you should get something like:

ps auxf | grep httpd | grep -v 'grep'
root     16955  0.0  0.2 275440 17996 ?        Ss   13:50   0:00 /usr/sbin/httpd -X -f /etc/httpd/conf/httpd.conf
www-data 16987  0.0  0.1 275472  7620 ?        S    13:50   0:00  \_ /usr/sbin/httpd -X -f /etc/httpd/conf/httpd.conf

Now, browsing the web, it seems that sometimes a second root process is spawned, maybe because of one specific module loaded in Apache that requires that.If you really want to track that you'll have to remove modules, remove advanced things (like SSl certificates, RewriteLock, etc).

You can also try a lsof -p PID on each process the check for differences.

Here are some other examples of this behavior:

But nobody has a real answer to that.

Check also which mpm is currently used (prefork, worker, event?)