Solved

Usage of negative pid in kill command

Posted on 2011-09-22
4
684 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 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
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.
Suggested Courses

738 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