sudo to kill output of ps, awk, xargs
This is an ugly hack, and kill
will complain, but it works (for me, at least):
sudo kill `ps -ae | grep foo` &>/dev/null
The &>/dev/null
part is optional; include it if you do not want to see all of kill
's complaints.
I know there is probably a better way of doing this, but this is what I use.
As already mentioned pgrep
and pkill
are your friends:
sudo pkill `pgrep -u root foo`
If for some reason you do not have pgrep
and pkill
, you can do something like this:
for n in $(ps -u root | grep foo | cut -d ' ' -f 2); do sudo kill $n; done