Why does apache2 have multiple processes?

Because that is how apache works: it is started as root and then spawns 'children' that are started as a normal user. Security wise is is a very good approach since the user apache2 should not be able to brick your system.

From the manual:

A single control process is responsible for launching child processes which listen for connections and serve them when they arrive. Apache httpd always tries to maintain several spare or idle server processes, which stand ready to serve incoming requests. In this way, clients do not need to wait for a new child processes to be forked before their requests can be served.

The StartServers, MinSpareServers, MaxSpareServers, and MaxRequestWorkers regulate how the parent process creates children to serve requests. In general, Apache httpd is very self-regulating, so most sites do not need to adjust these directives from their default values. Sites which need to serve more than 256 simultaneous requests may need to increase MaxRequestWorkers, while sites with limited memory may need to decrease MaxRequestWorkers to keep the server from thrashing (swapping memory to disk and back). More information about tuning process creation is provided in the performance hints documentation.

Now regarding this:

Which is the correct pid when I use kill command ?

There is no need to kill apache requests. I would suggest using sudo service apache restart and not to kill anything related to apache. Gracefully restarting a service should always be chosen over killing.


Apache starts automatically some child processes that apache can answer multiple request faster. So the daemon don't have to fork another new process for every new request.

Such a child process have a life cycle configured by several directives in your apache config.

You can see the hierarchy of the processes when you invoke ps like this:

root@host:~$ ps faux | grep apache
root      3122  0.0  0.5  37164 11172 ?        Ss   Aug09   1:55 /usr/sbin/apache2 -k start
www-data 21970  0.0  0.8  43636 17060 ?        S    Nov03   0:41  \_ /usr/sbin/apache2 -k start
www-data 27484  0.0  0.8  43372 16660 ?        S    10:41   0:04  \_ /usr/sbin/apache2 -k start
www-data 29631  0.0  0.7  43132 16360 ?        S    13:36   0:02  \_ /usr/sbin/apache2 -k start
www-data 29632  0.0  0.5  37644 10888 ?        S    13:36   0:03  \_ /usr/sbin/apache2 -k start
www-data 29696  0.0  0.8  43380 16644 ?        S    13:42   0:02  \_ /usr/sbin/apache2 -k start
www-data 30025  0.0  0.7  42584 15864 ?        S    14:10   0:02  \_ /usr/sbin/apache2 -k start
www-data 30026  0.0  0.8  43968 17216 ?        S    14:10   0:02  \_ /usr/sbin/apache2 -k start
www-data 30092  0.0  0.7  43348 16556 ?        S    14:13   0:01  \_ /usr/sbin/apache2 -k start
www-data 30184  0.0  0.8  43636 16884 ?        S    14:18   0:01  \_ /usr/sbin/apache2 -k start
www-data 30235  0.0  0.7  42576 15836 ?        S    14:23   0:01  \_ /usr/sbin/apache2 -k start

So you just have to "kill" the parent process. But in today's modern linux distributions we stop daemons in a more ecological way. To stop the apache daemon with all it's children processes:

sudo service apache stop