From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751503AbcLEOH2 (ORCPT ); Mon, 5 Dec 2016 09:07:28 -0500 Received: from mail-wj0-f173.google.com ([209.85.210.173]:33111 "EHLO mail-wj0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751100AbcLEOHZ (ORCPT ); Mon, 5 Dec 2016 09:07:25 -0500 MIME-Version: 1.0 In-Reply-To: <20161205110016.GA29776@redhat.com> References: <20161205104652.GA29197@redhat.com> <20161205110016.GA29776@redhat.com> From: Dmitry Vyukov Date: Mon, 5 Dec 2016 15:07:03 +0100 Message-ID: Subject: Re: Unkillable processes due to PTRACE_TRACEME again To: Oleg Nesterov Cc: Pavel Machek , Denys Vlasenko , jan.kratochvil@redhat.com, palves@redhat.com, Roland McGrath , syzkaller , LKML Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Dec 5, 2016 at 12:00 PM, Oleg Nesterov wrote: > On 12/05, Oleg Nesterov wrote: >> >> On 12/02, Dmitry Vyukov wrote: >> > >> > I am not on 2caceb3294a78c389b462e7e236a4e744a53a474 (Dec 1). And see >> > the same unwaitable zombie processes. >> >> This is another thing, and notabug. This is how ptrace works, >> >> > void *thr(void *arg) >> > { >> > ptrace(PTRACE_TRACEME, 0, 0, 0); >> > } >> > >> > int main() >> > { >> > int pid = fork(); >> > if (pid == 0) { >> > pthread_t th; >> > pthread_create(&th, 0, thr, 0); >> > usleep(100000); >> > exit(0); >> > } >> > usleep(200000); >> > kill(pid, SIGKILL); >> > int status = 0; >> > waitpid(pid, &status, __WALL); >> >> waitpid(pid) hangs because you need to reap the sub-thread first. > > I'm afraid I wasn't clear... > > So the child process has 2 threads, the leader thread L and the sub-thread T. > waitpid(pid == L->pid) will block until all the threads go away, but since T is > traced it won't autoreap, the tracer should do waitpid(T->pid) first to reap > this zombie. waitpid(-1) should work too. Do you mean that I need to replace: waitpid(pid, &status, __WALL); with: while (waitpid(-1, &status, __WALL) != pid) {} ? It seems to work. But want to make sure.