Solved

Usage of negative pid in kill command

Posted on 2011-09-22
4
591 Views
Last Modified: 2012-05-12
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
Comment
Question by:beer9
  • 2
4 Comments
 
LVL 4

Accepted Solution

by:
sakman earned 167 total points
Comment Utility
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
 
LVL 21

Assisted Solution

by:Papertrip
Papertrip earned 167 total points
Comment Utility
'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
 
LVL 38

Assisted Solution

by:wesly_chen
wesly_chen earned 166 total points
Comment Utility
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
 
LVL 38

Expert Comment

by:wesly_chen
Comment Utility
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

I am a long time windows user and for me it is normal to have spaces in directory and file names. Changing to Linux I found myself frustrated when I moved my windows data over to my new Linux computer. The problem occurs when at the command line.…
Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now