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.)
Asked
Active
Viewed 1.3k times
3 Answers
10
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

Kyle Brandt
- 83,619
- 74
- 305
- 448
1
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.

Zypher
- 37,405
- 5
- 53
- 95
-
1Personally, 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
1
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 :)

ewwhite
- 197,159
- 92
- 443
- 809