Kill a process run by a specific user
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.)
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
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.
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 :)