Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Let's say that I have several users running ''ruby'' processes simultaneously. How do I write a shell command to kill the ''ruby'' process of one particular user? (I'm on CentOS 5.5.)

share|improve this question
add comment

3 Answers 3

up vote 6 down vote accepted

pkill is good good for this:

pkill -u particularUser ruby

You can use pgrep with this as a test before you run it to see the process name and pid of what will be signaled:

pgrep -u particularUser -l ruby
share|improve this answer
    
Thanks, good answer. –  Trevor Burnham Aug 17 '10 at 16:01
add comment

You can use the -u switch to killall to limit the scope to a single users. So for user abc you could do: killall -u abc /usr/bin/ruby (or whatever will match the ruby proccesses)

from man killall:

-u, --user
Kill only processes the specified user owns. Command names are optional.

share|improve this answer
1  
Personally, I much prefer pkill over killall because (a) killall is evil on some Unixes other than Linux and (b) pkill has the pgrep alias that you can use to test that it's going to do the right thing. –  freiheit Aug 16 '10 at 16:48
add comment

As a worst-case, if you can login or su - as the user, you can issue the famed kill -9 -1 command AS the user to clean up their processes.

Do NOT run as root :)

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.