From: Chris Spiegel <linuxml@happyjack.org>
To: linux-kernel@vger.kernel.org
Subject: [PATCH] Exclude kernel threads from kill(-1, ..)
Date: Fri, 21 Apr 2006 17:31:00 -0700 [thread overview]
Message-ID: <20060422003100.GA14966@midgard.spiegels> (raw)
kill(-1, ..) currently will try to signal kernel threads, which of
course won't die off even with SIGKILL, meaning that ESRCH will never be
returned. Instead, allow kill() to return ESRCH if the only processes
left are simply unkillable (kernel threads). This does not violate
POSIX which says that "an unspecified set of system processes" may be
excluded when killing -1.
Signed-off-by: Chris Spiegel <linuxml@happyjack.org>
---
(please CC replies to me)
There is a comment in signal.c which says that Linux's kill(-1, ..) does
something that is probably wrong and should be like BSD or SysV. Well,
this is a bit more like the modern BSDs (possibly SysV, I'm not familiar
with it), although we still don't kill the calling process, a choice I
agree with.
This isn't just a pathological fix, it's a problem I ran into with the
following code (from NetBSD's /sbin/reboot):
for (i = 1;; ++i) {
if (kill(-1, SIGKILL) == -1) {
if (errno == ESRCH)
break;
goto restart;
}
if (i > 5) {
warnx("WARNING: some process(es) wouldn't die");
break;
}
(void)sleep(2 * i);
}
So it fixes a real-world (my world, anyway) problem.
--- linux-2.6/kernel/signal.c.orig 2006-04-21 15:44:17.618784128 -0700
+++ linux-2.6/kernel/signal.c 2006-04-21 16:20:52.269454557 -0700
@@ -1156,7 +1156,8 @@ static int kill_something_info(int sig,
read_lock(&tasklist_lock);
for_each_process(p) {
- if (p->pid > 1 && p->tgid != current->tgid) {
+ if (p->pid > 1 && p->tgid != current->tgid &&
+ p->mm != NULL) {
int err = group_send_sig_info(sig, info, p);
++count;
if (err != -EPERM)
reply other threads:[~2006-04-22 0:31 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20060422003100.GA14966@midgard.spiegels \
--to=linuxml@happyjack.org \
--cc=linux-kernel@vger.kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox