Jump to content
Sign in to follow this  
anyweb

how to kill a user

Recommended Posts

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

 

cheers

 

anyweb and thanks grepster

 

:)

  • Like 1

Share this post


Link to post
Share on other sites
ps -efj |grep user |awk '{print $2}'|xargs kill -9

 

cheers

 

anyweb and thanks grepster

 

:)

 

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:

 

pkill -u uid

 

done (you can do

pkill -u user

as well)

Share this post


Link to post
Share on other sites

nice follow up thanks

 

can you provide a working example ?

 

cheers

 

anyweb

Share this post


Link to post
Share on other sites

Sure....

 

pkill -u znx

 

Will kill all processes started by user 'znx'.

 

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)

Share this post


Link to post
Share on other sites

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

 

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

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).

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...