Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

In the man page, it says:

          0      All processes in the current process group are signaled

And I tried like this:

$ man kill &
[1] 15247
$
[1]+  Stopped                 man kill
$ kill 0
$ ps
15247 pts/41   00:00:00 man

As I understood, kill 0 will kill all processes in the current process, which includes pid15247. However, it didn't do anything in this example. Does anyone have ideas about how to use it?

share|improve this question

migrated from stackoverflow.com Mar 11 '13 at 5:45

This question came from our site for professional and enthusiast programmers.

    
What shell are you using? –  FatalError Mar 11 '13 at 5:05
    
@FatalError I'm using Bash –  Firegun Mar 11 '13 at 5:06

3 Answers 3

I couldn't find a note how kill 0 behaves in my kill man page (debian).

But I have two comments:

(1) "Process Group" might not be what you expect. You can display the Process Group ID (PGID) with ps -o "%p %P %r %c %a":

$ ps -o "%p %P %r %c %a"
  PID  PPID  PGID COMMAND         COMMAND
12124 12123 12124 zsh             -zsh
12212 12124 12212 man             man kill
12226 12212 12212 less            less
12302 12124 12302 ps              ps -o %p %P %r %c %a

So, the man together with the displaying pager tool (less) is in the same process group, but that is different from that of the shell (zsh in my case).

(2) There are probably two different kill commands. One built into bash (see bash(1), Section "SHELL BUILTIN COMMANDS") and the external /bin/kill. These two may behave differently! You can explicitly state which one you want to run by typing builtin kill or command kill instead of kill. The external command you can also run by specifying the path: /bin/kill.

share|improve this answer
    
PPID is the parent process ID, which is often, but not necessarily, the process group ID. The correct column is PGID, which does not appear in the default ps output; you need to use the -o option to construct a custom format that includes it. –  chepner Mar 11 '13 at 12:53
    
@chepner: You are absolutely right, thanks! I was confused by my Cygwin's ps(1) man page, which states: "-l, --long: show process uids, ppids, pgids, winpids". Shame on me, I edited my answer accordingly. However, my statement (only man+pager have the same PGID) is correct now, as intended. (Before even that sentence was wrong :-() –  mpy Mar 11 '13 at 13:19

The issue is not with 'kill 0', which works as expected, but with the fact that the target process is stopped.

Try this:

kill -9 0
share|improve this answer
    
The process doesn't terminates.. Maybe you fg that process and press q in man kill &. It's not killed by the command. –  Firegun Mar 11 '13 at 5:23

To stop all of your processes and log yourself off, enter:

kill -kill 0

This sends signal 9, the SIGKILL signal, to all processes having a process group ID equal to the senders process group ID. Because the shell cannot ignore the SIGKILL signal, this also stops the login shell and logs you off

This is IBM's AIX Manual, but perhaps the concept applies.

This functionality does not exist in Linux "kill" (as I can see); but this is how it's "kill" behaves:

Killing 0 isn't killing the pid 0. Instead it is an option in kill to kill all processes in the current group. With your command you are killing everything in the process group ID (GID) of the shell that issued the kill command.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.