mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Kyle Moffett <mrmacman_g4@mac.com>
To: Badari Pulavarty <pbadari@us.ibm.com>
Cc: lkml <linux-kernel@vger.kernel.org>
Subject: Re: 2.6.14-rc1 wait()/SIG_CHILD bevahiour
Date: Mon, 19 Sep 2005 14:01:07 -0400	[thread overview]
Message-ID: <CEA22AE9-C1D1-4621-B01A-F7D1F6F25110@mac.com> (raw)
In-Reply-To: <1127151573.1586.14.camel@dyn9047017102.beaverton.ibm.com>

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 <sys/types.h>
#include <sys/wait.h>

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



  reply	other threads:[~2005-09-19 18:01 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-09-19 17:39 Badari Pulavarty
2005-09-19 18:01 ` Kyle Moffett [this message]
2005-09-19 18:19   ` Badari Pulavarty
2005-09-19 19:14 ` Linus Torvalds
2005-09-19 23:34   ` Roland McGrath
2005-09-20 16:49     ` Badari Pulavarty
2005-09-19 20:53 ` Edgar Toernig

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CEA22AE9-C1D1-4621-B01A-F7D1F6F25110@mac.com \
    --to=mrmacman_g4@mac.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbadari@us.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®