Solved

Usage of negative pid in kill command

Posted on 2011-09-22
4
638 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
ID: 36584569
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
ID: 36584580
'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
ID: 36584599
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
ID: 36584620
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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Network Interface Card (NIC) bonding, also known as link aggregation, NIC teaming and trunking, is an important concept to understand and implement in any environment where high availability is of concern. Using this feature, a server administrator …
rdate is a Linux command and the network time protocol for immediate date and time setup from another machine. The clocks are synchronized by entering rdate with the -s switch (command without switch just checks the time but does not set anything). …
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

832 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