Return-Path: Delivered-To: apmail-httpd-dev-archive@www.apache.org Received: (qmail 52972 invoked from network); 12 Feb 2005 14:44:00 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 12 Feb 2005 14:44:00 -0000 Received: (qmail 46161 invoked by uid 500); 12 Feb 2005 14:43:57 -0000 Delivered-To: apmail-httpd-dev-archive@httpd.apache.org Received: (qmail 46136 invoked by uid 500); 12 Feb 2005 14:43:57 -0000 Mailing-List: contact dev-help@httpd.apache.org; run by ezmlm Precedence: bulk Reply-To: dev@httpd.apache.org list-help: list-unsubscribe: list-post: Delivered-To: mailing list dev@httpd.apache.org Received: (qmail 46122 invoked by uid 99); 12 Feb 2005 14:43:56 -0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests=RCVD_BY_IP,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (hermes.apache.org: domain of trawick@gmail.com designates 64.233.170.193 as permitted sender) Received: from rproxy.gmail.com (HELO rproxy.gmail.com) (64.233.170.193) by apache.org (qpsmtpd/0.28) with ESMTP; Sat, 12 Feb 2005 06:43:54 -0800 Received: by rproxy.gmail.com with SMTP id y7so455287rne for ; Sat, 12 Feb 2005 06:43:52 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:references; b=plXAwbKuiuiHxQcWcK5D3rmAIwW46hRm6hqf1W1f3Qkws+hRjwOlxLJOvDbMVm/m2s9G1TPG065vx8IItvcOlKvOjg6EV8hpRkrRZ0J9kl0t/VsRY3d/N9fAzN6nzIYmqvG8ya7K7e3jlUUjOEuwDiOWBY42GQlHwk01b46z0iM= Received: by 10.38.104.7 with SMTP id b7mr270153rnc; Sat, 12 Feb 2005 06:43:52 -0800 (PST) Received: by 10.39.2.68 with HTTP; Sat, 12 Feb 2005 06:43:52 -0800 (PST) Message-ID: Date: Sat, 12 Feb 2005 09:43:52 -0500 From: Jeff Trawick Reply-To: Jeff Trawick To: dev@httpd.apache.org Subject: Re: Terminating cgi scripts In-Reply-To: <420B5612.2090509@india.hp.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit References: <420B5612.2090509@india.hp.com> X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N On Thu, 10 Feb 2005 18:09:46 +0530, Kiran Mendonce wrote: > We had a customer scenario (on HP-UX) recently where cgi scripts that > were spawned by mod_cgid continued to run even when httpd was stopped. > The ppid of these scripts was automatically 1 when the httpd processes > terminated. The customer does not find any reason why these processes > need to continue to run especially since the scripts need to be run > again when httpd restarts. This does seem like a reasonable demand. certainly > > 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. > 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. > 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.