Index: kern_exit.c =================================================================== RCS file: /private/FreeBSD/src/sys/kern/kern_exit.c,v retrieving revision 1.228 diff -u -p -r1.228 kern_exit.c --- kern_exit.c 18 Mar 2004 18:15:58 -0000 1.228 +++ kern_exit.c 28 Mar 2004 16:23:15 -0000 @@ -421,15 +421,28 @@ exit1(struct thread *td, int rv) for (; q != NULL; q = nq) { nq = LIST_NEXT(q, p_sibling); PROC_LOCK(q); - proc_reparent(q, initproc); q->p_sigparent = SIGCHLD; /* * Traced processes are killed * since their existence means someone is screwing up. + * Since we reset the trace flag, the logic in wait4() + * would not be triggered to reparent the process to its + * original parent, so we must do this here. */ if (q->p_flag & P_TRACED) { + struct proc *t; + + if (q->p_oppid && (t = pfind(q->p_oppid)) != NULL) { + q->p_oppid = 0; + proc_reparent(q, t); + PROC_UNLOCK(t); + } else { + proc_reparent(q, initproc); + } q->p_flag &= ~P_TRACED; psignal(q, SIGKILL); + } else { + proc_reparent(q, initproc); } PROC_UNLOCK(q); }