From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932531AbVISSBl (ORCPT ); Mon, 19 Sep 2005 14:01:41 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S932535AbVISSBk (ORCPT ); Mon, 19 Sep 2005 14:01:40 -0400 Received: from smtpout.mac.com ([17.250.248.70]:28353 "EHLO smtpout.mac.com") by vger.kernel.org with ESMTP id S932534AbVISSBk (ORCPT ); Mon, 19 Sep 2005 14:01:40 -0400 In-Reply-To: <1127151573.1586.14.camel@dyn9047017102.beaverton.ibm.com> References: <1127151573.1586.14.camel@dyn9047017102.beaverton.ibm.com> Mime-Version: 1.0 (Apple Message framework v734) Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Message-Id: Cc: lkml Content-Transfer-Encoding: 7bit From: Kyle Moffett Subject: Re: 2.6.14-rc1 wait()/SIG_CHILD bevahiour Date: Mon, 19 Sep 2005 14:01:07 -0400 To: Badari Pulavarty X-Mailer: Apple Mail (2.734) Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org On Sep 19, 2005, at 13:39:33, Badari Pulavarty wrote: > Hi, > > I am looking at a problem where the parent process doesn't seem to > cleanup the exited children (with a webserver). We narrowed it down > to a simple testcase. Seems more like a lost SIG_CHILD. You don't get one SIG_CHLD per child that quits. The kernel may and probably will merge SIG_CHLD signals together if it has several queued before it gets a chance to deliver them to your process. This is true of _all_ signals. If you "kill -STOP 1234", then "kill -QUIT 1234", "kill -QUIT 1234", "kill -QUIT 1234", "kill -CONT 1234", the PID 1234 will have 3 signals delivered: The original untrappable SIGSTOP, the SIGCONT that causes it to resume, and a single SIGQUIT immediately following it. The correct and portable way to handle this is to put a loop in your SIGCHLD signal handler: #include #include void sigchld_handler(int signal) { pid_t pid; int status; while( -1 != (child = waitpid(-1, &status, WNOHANG)) ) { /* * Now "status" is the exit status of the child and * "pid" is its pid. See the waitpid() manpage for * macros you can use to get information from the * status variable. */ do_some_processing_of_exited_child(pid,status); } } Cheers, Kyle Moffett -- There is no way to make Linux robust with unreliable memory subsystems, sorry. It would be like trying to make a human more robust with an unreliable O2 supply. Memory just has to work. -- Andi Kleen