[TUHS] fork
Warner Losh via TUHS
tuhs at tuhs.org
Wed May 13 06:34:13 AEST 2026
On Tue, May 12, 2026 at 5:19 AM Peter Jeremy via TUHS <tuhs at tuhs.org> wrote:
> On 2026-May-12 10:19:25 +0200, Folkert van Heusden via TUHS <tuhs at tuhs.org>
> wrote:
> >Now something unexpected is happening: after a request, a "<defunct>"
> proces
> >is left in the process list. Usually that is caused by a fork() not being
> >join()ed afterwards. But in main() of httpdp I invoke signal(SIGCHLD,
> >SIG_IGN); so I thought I took care of that?
>
> For "modern" Unixes (e.g. FreeBSD and Linux), there's a SA_NOCLDWAIT flag
> for sigaction(2) that explicitly says setting SIGCHLD to SIG_IGN means that
> child processes will not become zombies but will instead be implicitly
> reaped immediately.
>
Yes. This was defined in System V (I think r4, but I'm not 100% sure).
4.4BSD
didn't have it. FreeBSD added it in 1997. Linux had it earlier due to its
affinity
to System V, though I've not done a deep dive on this yet.
> This doesn't exist in BSD2.11 and, as far as I can tell from looking
> through the sources, there's no equivalent behaviour: When a process exits,
> the process becomes a zombie and the parent is sent a SIGCHLD (see
> kern_exit.c::exit()). In psignal(), if a signal is marked SIG_IGN, the
> signal is completely ignored - there's no special handling of SIGCHLD.
> There's no obvious code to clean up zombie processes if the parent doesn't
> wait() for them.
>
Over simplifying a bit, 2.11BSD was 7th Edition, with lots of add-ons from
4.2BSD
and 4.3BSD, plus a number of pdp-11 only things that post-dated the 7th
edition (like
overlay support). Most of the kernel-side components originated from 4.2BSD
with a few updates from 4.3BSD. Since 4BSD at CSRG never had SA_NOCLDWAIT,
2.11 doesn't have it.
The zombies are only cleaned up when the parent exits and they wind up at
init.
Other reapers came much later.
Warner
More information about the TUHS
mailing list