How to Kill a Process by Name Instead of PID via Command Line

Jan 12, 2017 - 1 Comment

How to kill a process by name

Command line users rely on the ‘kill’ command to terminate a process as defined by the appropriate process identifier (PID). While there’s nothing wrong with targeting processes by their PID, another approach which is often easier is to target a process by name, rather than its unique identifier.

There are a few ways to kill a process by process name, we’ll review two primary methods using killall and pkill. These will work the same in Mac OS / X and linux, and they can be used to target GUI apps and processes as well as those running in the background or exclusively at the command line. Either command can be prefixed with sudo to terminate root level tasks or those owned by another user.

Killing a Process by Name with killall

The killall command is the most commonly used way to kill a process by its name:

  1. From the Terminal, type the following command (in this example using task “ExampleTask” as the targetted process to kill)
  2. killall ExampleTask

  3. Hit return to instantly kill the ‘ExampleTask’ process (replace ExampleTask with any other process name to kill it)

Remember, killing a process is instantaneous and unforgiving, it immediately terminates the process without saving any data. This can result in data loss and other irregularities if you’re not sure what you’re doing.

Kill a Process by Name with pkill

The pkill command also offers an approach to terminate processes by name rather than targeting a PID. One of the perks of pkill is that it makes it easier to target processes with spaces in their names since you only need to use quotes around the task name to kill.

  1. From the Terminal, type the following command:
  2. pkill "Example Process name agent"

  3. Hit Return to immediately terminate the named process

Like killall, pkill will immediately terminate the process that has been targeted with no confirmations, dialogs, saves, or anything else. The process just instantly ends, much like using force quit on apps from the task manager or Activity Monitor.

pkill is a powerful tool with many capabilities, if interested you can learn about using pkill with wildcards and using pkill to kill all processes belonging to a specific user.

Know of another way to target a process by name to kill it from the command line? Let us know in the comments below!

.

Related articles:

Posted by: Paul Horowitz in Command Line, Mac OS, Tips & Tricks

One Comment

» Comments RSS Feed

  1. Fred says:

    I have never used pkill. Killall is the same as UNIX/Linux.

    I created an alias called “unrun”. I like that better because I am a pacifist.

Leave a Reply

 

Shop on Amazon.com and help support OSXDaily!

Subscribe to OSXDaily

Subscribe to RSS Subscribe to Twitter Feed Follow on Facebook Subscribe to eMail Updates

Tips & Tricks

News

iPhone / iPad

Mac

Troubleshooting

Shop on Amazon to help support this site