Yes, I've seen that there's already a similar question, but I came across kill -- -0
and was wondering what --
is doing?
Asked
Active
Viewed 5,050 times
14

manifestor
- 2,473
2 Answers
17
In UNIX/Linux world two dashes one after other mean end of options. For example if you want to search for string -n
with grep
you should use command like:
grep -- -n file
If you want to get only the line number in above case you should use
grep -l -- -n file
So the command kill -- -0
try to send signal to process with ID -0
(minus zero)

Romeo Ninov
- 17,484
-
12As for what process 0 is: "If pid equals 0, then sig is sent to every process in the process group of the calling process." (
kill(2)
) – ilkkachu Dec 13 '17 at 16:40 -
Just for the record PID 0 is available in some UNIX OS (like Solaris) – Romeo Ninov Dec 13 '17 at 16:44
-
As some system/kernel process, I hope? Though FWIW, POSIX has almost the same description of killing pid 0, except that it mentions unspecified system processes. – ilkkachu Dec 13 '17 at 16:49
-
@ilkkachu: What would be a process group? Do you mean the Cgroup? Please be so kind an give an example where this use case occurs. Thanks. – manifestor Dec 13 '17 at 16:58
-
-
1Why would one want to pass PID of minus zero? Aren't integers on all CPUs running POSIX-compatible OSes today two's complement, thus lacking any special encoding for
-0
? – Ruslan Dec 13 '17 at 21:22 -
@ilkkachu That seems to conflict with the answer here, unless I misread: https://unix.stackexchange.com/q/169898/85039 – Sergiy Kolodyazhnyy Dec 14 '17 at 00:57
-
@SergiyKolodyazhnyy I don't see the conflict -
-0
the option argument is signal specifier 0, aka no signal but process checking (that answer), and-0
the non-option argument is the process group of the current process (this answer and ilkkachu's comment). – muru Dec 14 '17 at 04:01 -
@muru according to that answer -0 "...will not actually in fact send anything to your process's PID, but will in fact check whether you have permissions to do so", but ilkkachu says it's for sending signal to every proc in process group. So is it actually for sending or for checking ? – Sergiy Kolodyazhnyy Dec 14 '17 at 04:06
-
2@SergiyKolodyazhnyy
-0
the option will not send anything.-0
the non-option will. Hence the--
in the command here. – muru Dec 14 '17 at 04:08 -
7
In this case it is used to denote that the -0
is not an option being passed in. If you were to do kill -0
it would think of -0
as an option not as the PID being passed in.
For example if you did ls -- -l
it will look for a file named -l
as opposed to just listing the directory in long form.

namor
- 71
--
part), but doesn't explain-0
though – Sergiy Kolodyazhnyy Dec 14 '17 at 00:40-0
. Indeed, the question explicitly points to an existing question that covers that, too. – JdeBP Dec 14 '17 at 06:45