Bash Shell Awesomeness - Mass Killing Processes (On Ubuntu)(skorks.com)
skorks.com
Bash Shell Awesomeness - Mass Killing Processes (On Ubuntu)
http://www.skorks.com/2009/08/bash-shell-awesomeness-mass-killing-processes-on-ubuntu/
4 comments
... or use pkill:
pkill -9 -U lusername
Unlike in Linux, in most unices killall(1) terminates all the processes> Unlike in Linux, in most unices killall(1) terminates all the processes
Hehe... That reminds me of the day I learned that you shouldn't put . in your path, especially in the front.
It turns out that (old?) Red Hat machines had a script 'killall' in their /etc/init.d ...
Hehe... That reminds me of the day I learned that you shouldn't put . in your path, especially in the front.
It turns out that (old?) Red Hat machines had a script 'killall' in their /etc/init.d ...
God, that brings back memories of administrating Solaris boxes in high school. Once you reboot a primary web server twice, you never do it again.
Hey, You're right! Never noticed that -u option.
I must use killall 100 times a day :)
I must use killall 100 times a day :)
Or you could ask ps to do most of the work for you:
ps -u www-data -o pid --no-headers
That gives me just the PIDs of the processes run by www-data.Makes you wonder how much shell script code is written every year by people that have not yet cracked the manual on section '1'.
So much good stuff in there.
Good reminder to do a periodic review of that stuff, not all the options are easy to remember if you don't use them frequently enough.
So much good stuff in there.
Good reminder to do a periodic review of that stuff, not all the options are easy to remember if you don't use them frequently enough.
Actually, I can never remember any of the options. I find myself doing man FOO all the time and usually work under the assumption that there's probably already an option to do the thing I'm trying to do.
Kudos to the original poster. That sort of combining of small tools is what the NIX command-line is all about.
Kudos to the original poster. That sort of combining of small tools is what the NIX command-line is all about.
Thats a great one as well, didn't even realise ps could do that
[deleted]
su to that user and "kill 0" or safer "kill -1".
He should really use awk instead of cut.
or killall
and for awesomeness, he should use zsh.
bash is what you use for mediocrity.
Who modded that down? He really should be using awk instead of cut. It has better readability: "{print $2}" to print the second field vs. a set of magic numbers denoting a character field. It's vastly easier to write (again, the "second field" is intuitive). It's also more generally useful, meaning that it's a better tool to know; cut is very primitive.
That said, there are better ways still to solve this problem. Some of them were detailed above. One that wasn't was the fact that GNU ps has lots of filtering options itself, in this case:
That said, there are better ways still to solve this problem. Some of them were detailed above. One that wasn't was the fact that GNU ps has lots of filtering options itself, in this case:
ps -eo pid -U 1002
Does the work of the grep and cut from the original for you.
http://linux.die.net/man/1/killall