Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Usage of negative pid in kill command

Posted on 2011-09-22
4
Medium Priority
?
802 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 4

Accepted Solution

by:
sakman earned 668 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 668 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 664 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

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!

Question has a verified solution.

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

If you have a server on collocation with the super-fast CPU, that doesn't mean that you get it running at full power. Here is a preamble. When doing inventory of Linux servers, that I'm administering, I've found that some of them are running on l…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses

618 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