I'm fighting a bug in IntelliJ where nailgun instances screw up when SNAPSHOT dependencies are updated. I want to automate killing all processes that contain nailgun in their name.
So far I can get all relevant PIDs like so:
ps -x -o pid,cmd | grep nailgun | cut -f 1 -d ' '
This gives me for example:
26759
27852
28817
29963
31234
31577
I can go and run kill
for each of them manually, like kill 26759
etc. But piping doesn't work:
ps -x -o pid,cmd | grep nailgun | cut -f 1 -d ' ' | kill
This just prints
kill: usage: kill [-s sigspec | -n signum | -sigspec] pid | jobspec ... or kill -l [sigspec]
How do I pipe the list of PIDs to kill?
pgrep
, you might as well usepkill
. – Stephen Kitt Jun 11 '17 at 15:22whereis
, pipeline andls
. – Stephen Kitt Jun 11 '17 at 17:52ps -x -o pid,cmd | grep nailgun | grep -v 'grep' | cut -f 1 -d ' ' | xargs kill
. FYI for me I had tocut -f 2 -d ' '
as well. – mrjamesmyers Jan 04 '19 at 11:13