bin/108390: [libc] [patch] wait4() erroneously waits for all children when SIGCHLD is SIG_IGN [regression]

Jilles Tjoelker jilles at stack.nl
Sun Apr 5 09:10:03 PDT 2009


The following reply was made to PR bin/108390; it has been noted by GNATS.

From: Jilles Tjoelker <jilles at stack.nl>
To: bug-followup at FreeBSD.org, alan at 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


More information about the freebsd-bugs mailing list