Jeff Trawick wrote:
...
Thanks ! I did this and it worked.The problem occurs both with mod_cgi and mod_cgid. Being a novice, I have the following questions. It would be really helpful to get your take on the following : 1. How do I get all the child pids spawned by the cgid daemon and the httpd child (mod_cgi) so I can kill them when I get a signal ? Is it okay if I modify apachectl so that I can get all the processes that are owned by 'www' and still running using the 'ps' command and then kill them after "httpd -k stop" ?I wouldn't pursue that unless there is absolutely no practical way to fix the code. In the worst case, can't the MPM figure out right before exiting that it is the parent of some active processes, and continuing to exit will keep them stranded? But I'd suggest pursuing the mod_cgid issues first.2. If that is not acceptable, I would need to change the code. I looked at the mod_cgid sources and I found that the pids of all the processes that cgid spawns are hashed in the hash table script_hash. If I could make script_hash a static global variable, I could get the pids in the signal handler and kill the processes. I have changed the code and it is working. Would I be breaking something ?If the cgid daemon is about to exit, it is reasonable for it to wipe out any processes it has created and which are still active. But do as little as possible in a signal handler (i.e., avoid adding any logic there). When the existing signal hander is called, it sets a flag which causes the mainline logic to exit. You should see mod_cgid exiting the loop "while (!daemon_should_exit) {", and while still in that function you have addressibility to the hash table.
I did not know this. Thanks.3. We use the worker MPM. For mod_cgi, I would need to make changes in worker.c since there is no daemon here.It is a bad thing if worker.c has logic specific to CGIs. Also, it is invalid to use mod_cgi with a threaded MPM on Unix. Maybe it will seem to work, but bad things can happen under heavy load, with descriptors getting inherited by the wrong child processes.
I still want to know how I can get the process id in worker.c. I should be able to get it from some pool. But I am not able to figure out how. If you do know, or if theres some kind of document, that would help me too.In mod_cgi code, I find that everytime a process is spawned, apr_pool_note_subprocess() is called.On Unix, mod_cgi should only be used with a non-threaded MPM. And that non-threaded MPM (prefork) child process will not exit* without cleaning up the pool that the processes have been associated with. *if something is stalling and keeping the child process from exiting in a timely manner, the Apache parent will kill the child process, such that this cleanup will not be performed.
Thanks so much for responding.
- Kiran
