From mboxrd@z Thu Jan 1 00:00:00 1970 From: Oleg Nesterov Subject: Re: ptrace.2: PTRACE_KILL needs a stopped process too Date: Wed, 9 May 2012 23:14:29 +0200 Message-ID: <20120509211429.GA2455@redhat.com> References: <20091216004533.22261.qmail@kosh.dhis.org> <4FAAC706.6000808@redhat.com> <20120509201219.GA32051@redhat.com> <201205091241.59060.vapier@gentoo.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Content-Disposition: inline In-Reply-To: <201205091241.59060.vapier@gentoo.org> Sender: linux-kernel-owner@vger.kernel.org To: Mike Frysinger Cc: Pedro Alves , "Michael Kerrisk (man-pages)" , pacman@kosh.dhis.org, linux-man , lkml , Denys Vlasenko , Tejun Heo , Jan Kratochvil List-Id: linux-man@vger.kernel.org On 05/09, Mike Frysinger wrote: > > On Wednesday 09 May 2012 16:12:19 Oleg Nesterov wrote: > > On 05/09, Pedro Alves wrote: > > > On 05/09/2012 04:09 PM, Mike Frysinger wrote: > > > > probably not that big of a deal, but the reason i like using > > > > ptrace(PTRACE_KILL) over a raw kill() is that you are less likely to > > > > kill the wrong process by accident. maybe not that big of a deal in > > > > practice though. > > > > > > And you can do tgkill instead. It was specifically invented to handle > > > the reuse case. > > > > tgkill() can kill the wrong process/thread too, although it lessens the > > risk. > > > > But I don't really understand the problem. The traced thread can't go away > > until the tracer does wait/detach, and thus its pid can't be reused? > > or the process has received a SIGKILL for some reason And? In this case it will be killed, yes. But this zombie can't go away until the tracer does do_wait(). OK, the multi-threaded exec adds more fun. > > May be, "by accident" above means something else, not pid reuse... > > i like to assume that my code isn't going to be bug free, so the more > mechanisms i have in place to protect innocent bystanders the better :) > -mike >>From this pov PTRACE_KILL is safer, I agree ;) Oleg.