From: Oleg Nesterov <oleg@redhat.com>
To: Dmitry Vyukov <dvyukov@google.com>
Cc: Pavel Machek <pavel@ucw.cz>, Denys Vlasenko <dvlasenk@redhat.com>,
jan.kratochvil@redhat.com, palves@redhat.com,
Roland McGrath <roland@hack.frob.com>,
syzkaller <syzkaller@googlegroups.com>,
LKML <linux-kernel@vger.kernel.org>
Subject: Re: Unkillable processes due to PTRACE_TRACEME again
Date: Mon, 5 Dec 2016 17:59:58 +0100 [thread overview]
Message-ID: <20161205165957.GA13035@redhat.com> (raw)
In-Reply-To: <CACT4Y+a0R=88PWjPrz3qYZFn6rkm3+yH_sHhoqpVEv4WZT82Yg@mail.gmail.com>
On 12/05, Dmitry Vyukov wrote:
>
> On Mon, Dec 5, 2016 at 12:00 PM, Oleg Nesterov <oleg@redhat.com> 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) {}
> ?
Yes. Or, if you knew the pid of the traced thread you could do
// need to do this first, the traced sub-thread won't autoreap,
// and the leader which represents the whole process is not reapable
// until all other threads go away
waitpid(tracee_pid, &status, __WALL);
waitpid(pid, &status, __WALL);
Oleg.
prev parent reply other threads:[~2016-12-05 17:00 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-12-02 18:48 Unkillable processes due to PTRACE_TRACEME again Dmitry Vyukov
2016-12-02 21:02 ` Pavel Machek
2016-12-03 15:55 ` Dmitry Vyukov
2016-12-03 19:11 ` Pavel Machek
2016-12-05 10:46 ` Oleg Nesterov
2016-12-05 11:00 ` Oleg Nesterov
2016-12-05 14:07 ` Dmitry Vyukov
2016-12-05 16:59 ` Oleg Nesterov [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20161205165957.GA13035@redhat.com \
--to=oleg@redhat.com \
--cc=dvlasenk@redhat.com \
--cc=dvyukov@google.com \
--cc=jan.kratochvil@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=palves@redhat.com \
--cc=pavel@ucw.cz \
--cc=roland@hack.frob.com \
--cc=syzkaller@googlegroups.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.