0

If I execute the Following command all the process will be killed and the account is logged out.

Command:

kill -9 -1

It is similar to the logout command. In Unix, no such process having the pid as "-1". So, what is the reason for this result?

0

3 Answers 3

3

See the manual page (http://linux.die.net/man/2/kill)

If pid equals -1, then sig is sent to every process for which the calling process has permission to send signals, except for process 1 (init), but see below.

So I guess that is you out of the system - but life continues for the rest of us

PS: It is not graceful

Sign up to request clarification or add additional context in comments.

Comments

2

When the pid argument of kill is prefixed with a -, it sends the signal to the process group instead. Every process has a pid, but also a process group id.

You can see this by running this:

$ bash -c 'sleep 10 & sleep 1; ps -o pid,ppid,pgrp,cmd'
  PID  PPID  PGRP CMD
22471 22467 22471 -bash
22496 22471 22496 bash -c sleep 10 & sleep 1; ps -o pid,ppid,pgrp,cmd
22497 22496 22496 sleep 10
22499 22496 22496 ps -o pid,ppid,pgrp,cmd

Here you can see the bash -c has gotten its own process group (22496, same as its PID), and its two child processes (sleep and ps), has inherited this process group.

kill -TERM 22496 would send a TERM signal to the bash -c process with pid 22496, while kill -TERM -22496 would send a TERM signal to the three processes bash -c, sleep and ps.

-1 however, is a special case, that sends the signal to all processes you can send to.

Comments

-1

kill -9 -1 eliminates the need to hard reboot the system and is mainly useful to efficiently and cleanly terminate programs that have are not responding.

2 Comments

the syntax of kill command is "kill <SIGNAL> <PID>". Here signal is optional. So, what is -1 stands for.
kill -9 is not a clean way of ending a process. I is harsh

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.