pgrep and pkill: A Better killall?
Main Content
Just learned a new tool that has somehow escaped me the last 15 years. prep is a simple tool that lets you grep through the names of running processes, returning just the PIDs. pkill takes that a step further, killing the matched processes1. The cool thing is that both support tab-completion under zsh.
Quick Examples
To find all running processes with the name jekyll
Using the -l
switch shows the process name as well
Note how without the -l
switch we don’t know that we’re matching
FinderSyncExt
. Good thing we didn’t run pkill
yet!
To match exactly, the -x
switch is used. This can help solve the problem of
matching too greedily, especially when using pkill
.
Perhaps the too-greedy-by-default is why must instructions found on the web use killall over pkill. Still, I am liking the tab-completion offered by zsh.
-
A note of warning: pkill will kill processes that match only partially. So
pkill Finder
will killFinder
andFinderSynExt
processes. Be careful! ↩