Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

What does "kill 0" do?

785 views
Skip to first unread message

Kenny McCormack

unread,
Jun 27, 2017, 9:18:58 AM6/27/17
to
What does "kill 0" do?

The short answer seems to be: nothing.

Presumably, there is no process with pid == 0, but in general, killing a
non-existent pid gets an error message. But "kill 0" doesn't get err msg.

Note that "-1" is a "special pid", documented in "man kill", but there is
no mention of "0" as a "special". But here's the thing: I seem to remember
that, back in the early days of Unix, we'd do "kill 0" and it would kill
all (or almost all) of your processes. It was similiar (but different
in some detail(s)) to using a pid of "-1".

Has that functionality quietly gone by the by?

--
So to cure the problem of arrogant incompetent rich people we should turn
the government over to an arrogant incompetent trust fund billionaire
who knows nothing about government and who has never held a job in his
entire spoiled life?

Richard Kettlewell

unread,
Jun 27, 2017, 10:02:24 AM6/27/17
to

Scott Lurndal

unread,
Jun 27, 2017, 10:03:39 AM6/27/17
to
gaz...@shell.xmission.com (Kenny McCormack) writes:
>What does "kill 0" do?
>
>The short answer seems to be: nothing.
>
>Presumably, there is no process with pid == 0, but in general, killing a
>non-existent pid gets an error message. But "kill 0" doesn't get err msg.
>
>Note that "-1" is a "special pid", documented in "man kill", but there is
>no mention of "0" as a "special". But here's the thing: I seem to remember
>that, back in the early days of Unix, we'd do "kill 0" and it would kill
>all (or almost all) of your processes. It was similiar (but different
>in some detail(s)) to using a pid of "-1".

The kill(2) system call:

"If pid is 0, sig shall be sent to all processes
(excluding an unspecified set of system processes)
whose process group ID is equal to the process group
ID of the sender, and for which the process has permission
to send a signal."

The kill(1) command:

"For each pid operand, the kill utility shall perform actions
equivalent to the kill() function defined in the System
Interfaces volume of POSIX.1-2008 called with the following arguments:
- The pid provided to the kill command
- The signal number provided to the kill command.

Casper H.S. Dik

unread,
Jun 27, 2017, 10:13:41 AM6/27/17
to
gaz...@shell.xmission.com (Kenny McCormack) writes:

>What does "kill 0" do?

>The short answer seems to be: nothing.

>Presumably, there is no process with pid == 0, but in general, killing a
>non-existent pid gets an error message. But "kill 0" doesn't get err msg.

>Note that "-1" is a "special pid", documented in "man kill", but there is
>no mention of "0" as a "special". But here's the thing: I seem to remember
>that, back in the early days of Unix, we'd do "kill 0" and it would kill
>all (or almost all) of your processes. It was similiar (but different
>in some detail(s)) to using a pid of "-1".

>Has that functionality quietly gone by the by?

If pid is 0, sig will be sent to all processes excluding special pro-
cesses (see Intro(2)) whose process group ID is equal to the process
group ID of the sender.

(Solaris 11.3 manual page, similar working can be found in the
OpenGroup manual page)

Casper

Kaz Kylheku

unread,
Jun 27, 2017, 10:17:40 AM6/27/17
to
On 2017-06-27, Kenny McCormack <gaz...@shell.xmission.com> wrote:
> What does "kill 0" do?

POSIX definition/requirements:


The kill utility shall send a signal to the process or processes specified
by each pid operand.

For each pid operand, the kill utility shall perform actions
equivalent to the kill() function defined in the System Interfaces
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
volume of POSIX.1-2008 called with the following arguments:

The value of the pid operand shall be used as the pid argument.

The sig argument is the value specified by the -s option, - signal_number option, or the - signal_name option, or by SIGTERM, if none of these options is specified.

Source: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/kill.html

Stephane Chazelas

unread,
Jun 27, 2017, 10:20:10 AM6/27/17
to
2017-06-27 13:18:56 +0000, Kenny McCormack:
> What does "kill 0" do?
[...]

It kills your whole process group.

At the prompt of an interactive shell, for shells that don't
have "kill" builtin "kill 0" will run the kill command in a
process group of its own so kill will just kill itself.

For shells that have "kill" builtin, for "kill 0" alone, that
will send SIGTERM to the process group of the shell, usually
only the shell process, but if your shell was started for
instance as:

(sleep 1000 & bash)

at the prompt of another interactive shell, both bash and sleep
will be in the same process group so SIGTERM will be sent to
both.

Interactive shells usually ignore SIGTERM and many other signals
in the main process which is probably why it appears to do
nothing for you.

kill -s HUP 0

would terminate the shell.

In things like:

sleep 10 | kill 0

The behaviour will depend on whether the shell runs that "kill
0" in the main process (ksh, zsh), or in another one that will
be a member of the process group for that job (bash).

--
Stephane

Nicolas George

unread,
Jun 27, 2017, 11:21:50 AM6/27/17
to
Stephane Chazelas , dans le message
<20170627141...@chaz.gmail.com>, a écrit :
> [...]

Why are there five people to answer someone too lazy to make the
simplest web search?

Kenny McCormack

unread,
Jun 27, 2017, 12:49:31 PM6/27/17
to
In article <5952780b$0$3638$426a...@news.free.fr>,
1) Because that's what Usenet is for. If you don't like it, well you know
what you can do with it and where you can stick it.

2) Because I can google up gibberish as well as anyone. Obviously, I was
interested in a real answer, not gibberish.

3) Stephane Chazelas is the only person who gave a non-gibberish answer,
and for that I am grateful.

--
(Cruz certainly has an odd face) ... it looks like someone sewed pieces of a
waterlogged Reagan mask together at gunpoint ...

http://www.rollingstone.com/politics/news/how-america-made-donald-trump-unstoppable-20160224

Nicolas George

unread,
Jun 27, 2017, 5:44:09 PM6/27/17
to
Kenny McCormack, dans le message <oiu2al$drl$1...@news.xmission.com>, a
écrit :
> 1) Because that's what Usenet is for.

No.

> 2) Because I can google up gibberish as well as anyone. Obviously, I was
> interested in a real answer, not gibberish.

Nice. Next time you ask a stupid question, I'll answer gibberish on
purpose.
0 new messages