• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 835
  • Last Modified:

Usage of negative pid in kill command

I have seen in few example where the negative pid was used with 'kill' command to kill all process of a user. Could someone please let me know how it can be done?


Will kill all your processes, including the shell you're on/your ssh connection 
kill -9 -1 -1

to kill all d process including login shell:
kill -9 0 

Open in new window


Could someone please let me know how does it works? using above example how can I kill all the process of a particular uid/user?
0
beer9
Asked:
beer9
  • 2
3 Solutions
 
sakmanCommented:
From the kill man page:

Negative PID values  may  be  used  to  choose  whole process  groups; see the PGID column in ps command output. A PID of -1 is special; it indicates all processes except the kill process  itself  and init.

0
 
PapertripCommented:
'kill -9 -1'  will kill all processes that the user who issued it is able to.  Check out pkill instead.

Kill all processes with an effective user ID owner of 'bob'
pkill -u bob

Open in new window

Kill all processes with a real user ID of 'bob'
pkill -U bob

Open in new window


You can put the signal after pkill, like pkill -HUP.

man pkill

0
 
wesly_chenCommented:
a regular user can only kill the process owned by that user.
kill -9 -1
   will kill all the user processes with pid larger than 1

If you run this as root, you are pretty much kill everything exit "init" (daemon root) process.


kill -9 0
  0 mean kill all processes in the current process group
0
 
wesly_chenCommented:
Let run some commands so you can get the picture

echo $$    # get your current shell pid , say 1234
pstree -pl -H 1234   # show the process tree, which 1234 branch highlighted.

say

bash (1234) ----pstree( 1239)
                   |--java (1235)
                   |--perl (1236)

So, the current process goup is root as 1234 and include child processes 1235, 1236, and 1239.

When you issue
kill -9 0
  it kills processes  1239, 1235, 1236 and 1234.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now