The following command will display all the PID's running for vmstat1:
ps -ef | grep "vmstat 1" | awk '{ print $2 }'
My question is, how do I kill them all, if there's like 20 of them at once?
|
If your command produces list of PIDs, then simply pipe it into:
Note that your command will match the grep command as well, so consider adding something like |
|||
|
|
Just use
Also note that your
Or
|
|||||||||
|
|
If you are already using awk, you can do
It will output a list of kill commands, and as every one of the commands kills a single process, you will not run into potential argument list too long (though it's highly unlikely when going over running processes), and I added a pattern to avoid matching the grep process itself, as killing it may cut your list short. |
|||||||
|
kill $(pidof vmstat)orpidof vmstat | xargs kill? – Kotte Dec 5 '12 at 10:06