If a process acquires reaper status with procctl (or if it's init), then when one of its children exits, its children, including zombies, get reparented. If a zombie gets reparented, the reaper receives no notification, so unless it's looping around a wait* for unspecified children, the zombie won't get reaped until the reaper exits. This doesn't seem to be a problem for init, which does indeed loop around waitpid(-1,0,0). However, it makes it hard for a correct program which acquires reaper status to do anything interesting, as such a program should not block on anything but a wait* call unless it can guarantee that none of its descendants will exit with zombies, as otherwise the system can accumulate zombies.
A commit references this bug: Author: kib Date: Mon Dec 12 11:11:50 UTC 2016 New revision: 309886 URL: https://svnweb.freebsd.org/changeset/base/309886 Log: When a zombie gets reparented due to the parent exit, send SIGCHLD to the reaper. The traditional reaper init(8) is aware of zombies silently reparented to it after the parents exit, it loops around waitpid(2) to collect them. For other reapers, the silent reparenting is surprising and collecting zombies requires a thread blocking in waitpid(2) just for that purpose. It seems that sending second SIGCHLD is a better workaround than forcing all reapers to obey the setup. Reported by: Michael Zuo <muh.muhten@gmail.com>, jilles PR: 213928 Reviewed by: jilles (previous version) Sponsored by: The FreeBSD Foundation MFC after: 2 weeks Changes: head/sys/kern/kern_exit.c
A commit references this bug: Author: jilles Date: Mon Dec 12 22:51:29 UTC 2016 New revision: 309957 URL: https://svnweb.freebsd.org/changeset/base/309957 Log: Add tests for reaper receiving SIGCHLD (r309886). PR: 213928 MFC after: 2 weeks Changes: head/tests/sys/kern/reaper.c
Fixed in head, MFC pending.
A commit references this bug: Author: jilles Date: Mon Dec 26 14:39:05 UTC 2016 New revision: 310601 URL: https://svnweb.freebsd.org/changeset/base/310601 Log: MFC r309957: Add tests for reaper receiving SIGCHLD (r309886). PR: 213928 Changes: _U stable/11/ stable/11/tests/sys/kern/reaper.c
A commit references this bug: Author: jilles Date: Mon Dec 26 17:26:25 UTC 2016 New revision: 310610 URL: https://svnweb.freebsd.org/changeset/base/310610 Log: MFC r309957: Add tests for reaper receiving SIGCHLD (r309886). PR: 213928 Changes: _U stable/10/ stable/10/tests/sys/kern/reaper.c
Fixed in head, stable/11 and stable/10.
This has an apparent race and potential fix at https://lists.freebsd.org/pipermail/freebsd-current/2017-March/065123.html