[TUHS] fork
rob--- via TUHS
tuhs at tuhs.org
Tue May 12 22:38:14 AEST 2026
I remember having to use a double fork() in the 90’s which I think maybe to solve a problem like this that the top process can fork() and wait() but the child fork(’s again and exits so that the death of the grandchild process gets cleaned by by init.
Regards, Rob.
> On 12 May 2026, at 12:18, 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.
>
> 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.
>
> --
> Peter Jeremy
More information about the TUHS
mailing list