Date: Sun, 5 Apr 2009 16:10:02 GMT From: Jilles Tjoelker <jilles@stack.nl> To: freebsd-bugs@FreeBSD.org Subject: Re: bin/108390: [libc] [patch] wait4() erroneously waits for all children when SIGCHLD is SIG_IGN [regression] Message-ID: <200904051610.n35GA2eA078669@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
The following reply was made to PR bin/108390; it has been noted by GNATS.
From: Jilles Tjoelker <jilles@stack.nl>
To: bug-followup@FreeBSD.org, alan@pair.com
Cc:
Subject: Re: bin/108390: [libc] [patch] wait4() erroneously waits for all
children when SIGCHLD is SIG_IGN [regression]
Date: Sun, 5 Apr 2009 18:08:46 +0200
POSIX seems to agree with what FreeBSD does. The change you refer to
just makes ignoring SIGCHLD do the same as SA_NOCLDWAIT, i.e. avoid
creating zombies from terminated child processes.
Fact of the matter is that signal(SIGCHLD, SIG_IGN) and SA_NOCLDWAIT are
pretty useless, even if this were to be "fixed". If the child process
terminates while you are not executing waitpid(), the status is just
lost and it is even possible for a new child process to get the same
pid. Also think of functions like system(3), wordexp(3) and grantpt(3)
(the latter only on freebsd 5, 6 and 7), which create child processes to
do some of their work.
If you want to check if the pid still exists (beware of pid reuse), use
kill(pid, 0); to wait (not portably and with the same caveat), use
kqueue/kevent with EVFILT_PROC.
Additionally, if your code does not have to be portable, you can use
rfork(2) with the RFNOWAIT flag to avoid zombie creation for specific
child processes only. If that's not possible, consider forking twice and
waiting for the first child immediately or doing execl("/bin/sh", "sh",
"...&", (const char *)NULL); in a child process.
--
Jilles Tjoelker
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200904051610.n35GA2eA078669>
