From 545d31229353b58c550628b5eefff3436dc3ec66 Mon Sep 17 00:00:00 2001 From: Konstantin Belousov Date: Mon, 12 Dec 2016 11:11:50 +0000 Subject: [PATCH] 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 , jilles PR: 213928 Reviewed by: jilles (previous version) Sponsored by: The FreeBSD Foundation MFC after: 2 weeks --- sys/kern/kern_exit.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/sys/kern/kern_exit.c b/sys/kern/kern_exit.c index f4f453c3556..3e56ae3bef7 100644 --- a/sys/kern/kern_exit.c +++ b/sys/kern/kern_exit.c @@ -455,6 +455,11 @@ exit1(struct thread *td, int rval, int signo) if (!(q->p_flag & P_TRACED)) { proc_reparent(q, q->p_reaper); + if (q->p_state == PRS_ZOMBIE) { + PROC_LOCK(q->p_reaper); + pksignal(q->p_reaper, SIGCHLD, q->p_ksi); + PROC_UNLOCK(q->p_reaper); + } } else { /* * Traced processes are killed since their existence