httpd-modules-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Yann Ylavic <>
Subject Re: child_init hook: Main vs. MPM processes
Date Mon, 14 Dec 2020 12:38:43 GMT
Hi Florian,

On Mon, Dec 14, 2020 at 12:11 PM Florian Wagner <> wrote:
> is there a simple way to detect in a child_init hook if the current
> process is also the main server process (the one that runs the
> pre_config hook).

It depends on the MPMs your module is targeting.
For unix MPMs (which fork() children processes) the config hooks are
called only by the parent process, but others like MPM winnt do call
them (plus child_init) in the child process too (there is only one
child on winnt, and threads to handle the connections/requests)

> At least for debug mode (-X commandline switch) both pre_config and
> child_init are being both run for that single process and there's some
> stuff I need to do in my module that only ever should be run in child
> processes.
> I could store the main process pid in get pre_config hook and compare
> it with getpid() result in the child_init but maybe there's a more
> elegant solution?

With unix MPMs, pre/post_config and child_init hooks run in the same
process only happen for ONE_PROCESS mode (-X), so the check could be
ap_exists_config_define("ONE_PROCESS") to determine that.

With MPM winnt there is no inheritance/fork() of the parent resources
on Windows so I don't know if your do-that-in-the-child-only design
applies there anyway.
The child process can be identified with "getenv("AP_PARENT_PID") !=
NULL" if you need it, but as said above it does not mean that config
hooks are not run..


View raw message