Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 2 Sep 1997 10:37:58 +0930
From:      Greg Lehey <grog@lemis.com>
To:        "Jamil J. Weatherbee" <jamil@counterintelligence.ml.org>
Cc:        freebsd-hackers@FreeBSD.ORG
Subject:   Re: SIGCLD
Message-ID:  <19970902103758.36370@lemis.com>
In-Reply-To: <Pine.BSF.3.96.970901161354.2293B-100000@counterintelligence.ml.org>; from Jamil J. Weatherbee on Mon, Sep 01, 1997 at 04:17:21PM -0700
References:  <Pine.BSF.3.96.970901161354.2293B-100000@counterintelligence.ml.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, Sep 01, 1997 at 04:17:21PM -0700, Jamil J. Weatherbee wrote:
>
> I guess SIGCLD is really SIGCHLD under freebsd, no?

Close.

> I was looking at a daemon skeleton out of a Stevens book on Network
> programming, he specifically sets up a function that calls wait3 so that
> child zombies aren't left around --- however the signal man page for
> freebsd calls this SIGCLD and says that it is discarded by default which
> would suggest to me that wait3() is unnecessary if you are not interested
> in the status of the child.

The semantics of SIGC[H]LD differ greatly between System V and BSD.
Here's a quote from "Porting UNIX Software", page 213:

 System V treats the death of a child differently from other
 implementations: The System V signal SIGCLD differs from the BSD and
 POSIX.1 signal SIGCHLD and from all other signals by remaining active
 until you call wait.  This can cause infinite recursion in the signal
 handler if you reinstate the signal via signal or sigset before
 calling wait.  If you use the POSIX.1 sigaction call, you don't have
 to worry about this problem.

 When a child dies, it becomes a zombie.  As all voodoo fans know, a
 zombie is one of the Living Dead, neither alive nor dead.  In UNIX
 terminology, when a child process dies it becomes a zombie: the text
 and data segments are freed, and the files are closed, but the
 process table entry and some other information remain until it is
 exorcized by the parent process, which is done by calling wait.  By
 default, System V ignores SIGCLD and SIGCHLD, but the system creates
 zombies, so you can find out about child status by calling wait.  If,
 however, you change the default to explicitly ignore the signal, the
 system ignores SIGCHLD and SIGCLD, but it also no longer creates
 zombie processes.  If you set the disposition of SIGCHLD and SIGCLD
 to ignore, but you call wait anyway, it waits until all child
 processes have terminated, and then returns -1 (error), with errno
 set to ECHILD.  You can achieve the same effect with sigaction by
 specifying the SA_NOCLDWAIT flag in sa_flags.  There is no way to
 achieve this behaviour in other versions of UNIX: if you find your
 ported program is collecting zombies (which you will see with the ps
 program), it might be that the program uses this feature to avoid
 having to call wait.  If you experience this problem, you can solve
 it by adding a signal handler for SIGCLD that just calls wait and
 returns.

 The signal number for SIGCLD is the same as for SIGCHLD.  The
 semantics depend on how you enable it: if you enable it with signal,
 you get SIGCLD semantics (and unreliable signals), and if you enable
 it with sigaction you get SIGCHLD and reliable signals.  Don't rely
 on this, however.  Some versions of System V have special coding to
 ensure that a separate SIGCLD signal is delivered for each child that
 dies.

Greg



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?19970902103758.36370>