From owner-freebsd-bugs@FreeBSD.ORG Sun Apr 5 16:10:02 2009 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id EA0441065670 for ; Sun, 5 Apr 2009 16:10:02 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id D71638FC19 for ; Sun, 5 Apr 2009 16:10:02 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.14.3/8.14.3) with ESMTP id n35GA2Ns078670 for ; Sun, 5 Apr 2009 16:10:02 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.3/8.14.3/Submit) id n35GA2eA078669; Sun, 5 Apr 2009 16:10:02 GMT (envelope-from gnats) Date: Sun, 5 Apr 2009 16:10:02 GMT Message-Id: <200904051610.n35GA2eA078669@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org From: Jilles Tjoelker Cc: Subject: Re: bin/108390: [libc] [patch] wait4() erroneously waits for all children when SIGCHLD is SIG_IGN [regression] X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Jilles Tjoelker List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 05 Apr 2009 16:10:03 -0000 The following reply was made to PR bin/108390; it has been noted by GNATS. From: Jilles Tjoelker 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