How to kill many instances of a process at one go?
-
14-02-2021 - |
Question
I have several instances of a process (i.e. with a common command line). I would like to kill all of them at one go. How to achieve it?
Solution
Options:
- killall
- ps|awk|xargs kill
- tag-and-kill in htop
Killall is super powerful, but I find it hazardous to use indiscriminately. Option 2 is awkward to use, but I often find myself in environments that don't have killall; also, leaving out the xargs bit on the first pass lets me review the condemned processes before I swing the blade. Ultimately, I usually favour htop, since it lets me pick and choose before hitting the big "k".
OTHER TIPS
You are probably looking for the killall
command. For example:
killall perl
Would kill off all perl processes that are running on your machine. See http://linux.die.net/man/1/killall for more details.
killall
will do that for you. Use man killall
for the options but I usually do:
killall myProgName
Just be very careful (eg, use ps
first to make sure it will only kill what you want).
NOTE: killall is the answer... IF you're on Linux. SysV also has a killall command, but it does a very, very different thing: it's part of the shutting-down-processes-prior-to-system-halt. So, yes, killall's the easiest, but if you often shuttle between Linux and SysV systems, I might recommend writing up a quick script to do what you want, instead.