More efficient process killing

More efficient process killing

When people want to kill processes from the command line, I typically see them:

  • Run the ps command, with or without flags, and with or without grep
  • Sift through the results if there is more that one
  • Grab the pid and run “kill <pid>
  • Repeat the steps to kill other similar processes

There are a few other commands that are more sophisticated than kill and will save you time.

killall

# kill all processes with that name (so you don't need the PID)
killall <exact process name>

# kill all processes that match a regex
killall -m <expression>

# Test the command ahead of time rather than running it
killall -s

pkill (and pgrep)

# show all processes that match the expression
pgrep <expression>

# kill processes that match
pkill <expression>

# match full argument lists, so you could kill processes within a specific folder hierarchy, for example
pkill -f <expression>

Activity Monitor, duh

Save some headache and try Activity Monitor. You can search and sort a process list easily, kill a process, or send a signal, choosing from a list of possible signals. Here’s how it looks.