Find and Terminate Processes from the Linux or Mac OS Command Line
Updated by Sam Foo Written by Sam Foo
This Quick Answer explores some ways to locate and terminate a process from the command line. While there are graphical utilities such as Activity Monitor on Mac OS or Task Manager on Windows, such programs compromise control over processes in exchange for convenience. The command line offers many options for closing a process.
Find Process ID (PID)
A common pattern for ending a process is though its Process ID (PID). There are a variety of ways to find the PID.
If the process name is known,
pgrep will search currently running processes for the name:
pgrepis not installed by default on MacOS. This can be installed along with
pfindwith Homebrew via:
brew install proctools
Another way to list running processes for all users is through
ps aux. The output can be piped to grep in order to search for a process:
ps aux | grep firefox
Terminate the Process with kill or killall
Once the PID is found, send the kill signal with
kill. Replace the
[PID] in this example with the PID found in the previous steps:
There may be cases where there are multiple instances of the same program running or processes being continuously spawned. In such cases,
killall is an option:
killall [process name]
For a more information on
killall, see our guide on how to Use Killall and Kill Commands to Stop Processes on Linux.
Join our Community
This guide is published under a CC BY-ND 4.0 license.