Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to kill a user
#1



Code:
ps -efj |grep user |awk '{print $2}'|xargs kill -9




 

cheers

 

anyweb and thanks grepster

 

:)

Reply
#2

Quote:
Code:
ps -efj |grep user |awk '{print $2}'|xargs kill -9

<div>


 

cheers

 

anyweb and thanks grepster

 

:)








</div>
 

i would like to point out dangers in using this. one if you have two users with names that are close (eg user user1) and you attempt to kill all 'user's procs... user1's will go too. two if the command line has 'user' in it (eg 'sshd: user [priv]' normally a root proc) that will go too (or for the fact user turns up anywhere else in the line).

 

this one-liner is just a little too eager. a command called pkill can solve this though:

 



Code:
pkill -u uid




 

done (you can do

Code:
pkill -u user


as well)

Reply
#3

nice follow up thanks

 

can you provide a working example ?

 

cheers

 

anyweb

Reply
#4

Sure....

 



Code:
pkill -u znx




 

Will kill all processes started by user 'znx'.

 



Code:
pkill -u 1982




 

Will kill all processes started by the user with the UID of 1982.

 

Actually just as a side note. If you have a daemon started by say root and that daemon starts processes under a different user then you can find processes starting back up immediately after the pkill (e.g. apache)

Reply
#5

Firstly, this should be "how to STOP PROCESSES", rather than users.

 

Secondly, to retrieve a user's processes, use:



Code:
ps -fu USERNAME




Since then only processes owned by that user will be returned, rather than processes that match the username somewhere in the line (the user1/user10 problem)

 

Thirdly, I'd not do a "kill -9". Try to do an ordinary kill (-15) first to allow the process to quit gracefully. "-9" will leave all kinds of rubbish left behind (open DB connections, temporary files, orphaned processes, persistent filelocks, etc).

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)