I’ve moved on from ps aux | grep -i processname; kill PID
. The Mac (along with many other Unix-likes) has two handy utilities: pgrep
and pkill
. pgrep
does a case-insensitive search for processes matching the expression you provide, and returns all matching PIDs, one per line. pkill
does the same search, but just kills the matching processes instead of returning the PIDs.
A common use case for me is middleman
hanging when I change the config.rb
. I could kill it using the following:
kill `pgrep middleman`
pkill middleman
One of the benefits of using pkill
is that you can run the command interactively. Handy if you end up searching on the scripting language running the process, rather than something a bit more unique.