How to kill a process in OS X

ActivityMonitorIconXWhen an application hangs on your Mac, sometimes the quickest fix is to force the application to quit. In most cases, this will free the system and allow you to re-launch the program to get on with your work. There are three main ways to force-quit a program in OS X. The first is the Force-Quit menu, activated by pressing Option-Command-Escape or by choosing it from the Apple menu. With this, you can quit OS X application programs launched in your user account.

Unfortunately the Force-Quit panel is reserved for user applications and will not allow you to tackle a hanging background task (of which there are many in OS X), so to check for and manage these, you will need another approach.

The next level of application management is to use the Activity Monitor utility (in the Applications > Utilities folder), in which you can similarly select a program and click the “quit” toolbar button (which looks like an X) to close it. The benefit of Activity Monitor is it allows you to view system processes, background tasks, and applications running in other user accounts, and obtain their process IDs (PID) to further manage the process, if necessary.

Finally, if you are familiar with the Terminal, you can also use it to quit a program. There are two main commands for doing so: kill, and killall. The killall command allows you to specify a program or process by name, which will send a termination signal to the first instance of the process name:

killall processname
Force-quit window in OS X

The force-quit window will only show current user applications, which has its limits, despite its convenience.

A common use of this is to re-launch the Finder, Dock, or similar application in OS X, especially after making manual changes to settings files for these programs:

killall Finder
killall Dock

On the other hand, the use of “kill” requires you to specify the PID of the given process (most easily found in Activity Monitor), and will similarly send a termination signal to the process:

kill PID

Terminating vs Killing

When you use these options to force-quit a program, you are using one of two methods the system has for closing a program. The default is to send a termination signal (TERM, or signal ID 15) to the program. This approach is a “soft” quit, that is used when you press Command-Q, when you use “kill” or “killall” as indicated above, or when you use Activity Monitor and choose “Quit” instead of “Force-Quit” to close a program.

Signals in Activity Monitor

With a process selected in Activity Monitor, you can use the View menu to send signals to it, which will trigger anything from a reset, to a hard kill of the program.

The TERM signal is best to use; however, it will not clear some application hangs, in which case attempts at it will not close the program, and it will remain showing in Activity Monitor. To overcome this, you can send the program the alternative KILL signal (signal ID 9), which is an unequivocal kill for the program. To do this, when you select a process and click the “X” toolbar button in Activity Monitor, choose “Force-Quit” instead of “Quit.” Alternatively, if you use the OS X Terminal, then you can specify the KILL signal in one of two ways:

kill -9 PID
kill -KILL PID

Often when you try to force-quit a program and you are not seeing any success with other methods, use Activity Monitor to look up its PID and then use this form of the “kill” command to close the program.

Overcoming concerns with force-quitting programs

You may have valid concerns about arbitrarily killing a program, and especially a background task on your system. However, if any of these are hanging and appearing in red text in Activity Monitor, then for the most part they are as good as dead to the system. The system regularly checks in with these programs to get status updates and be able to send and receive information from them. If the program is unresponsive, then the system gives up on the program, meaning it is as good as dead to the rest of the system. If the program recovers then the system will likely re-employ its services, but while it is hung up the system cannot do anything with it. Therefore, regardless of whether the program is a user application or a background task, if it appears in red in Activity Monitor, then force quitting it will likely only help the system recover from the hang, and is a good first-step to take before having to restart your Mac.

For background tasks, OS X is built to recover from hangs and crashes in supportive services, and the stability of the core system depends on only a few of these (specifically kernel_task which you cannot force quit, and “launchd”). Therefore, force-quitting most background tasks will only interrupt a service, and not suddenly cause a system-wide crash. Furthermore, OS X should automatically re-launch important tasks, to re-establish the services they provide. This may be done immediately, on-demand, or at a set interval.

Kill signals explained

There are several different signals that you can send to a process using the “kill” command in order to quit it, and also with Activity Monitor (by selecting a process and choosing Send Signal To Process in the View menu. These include the following options, which serve different purposes:

  • (1) HUP — tell a process to quickly restart.
  • (2) INT — tell a process to stop what it’s doing (similar to pressing Control-C in the Terminal), though this can be overridden.
  • (3) QUIT — tell a process to perform some cleanup routines and then stop, though this can be overridden.
  • (6) ABRT — have the process quit itself (this may trigger a crash report in OS X).
  • (9) KILL — give the process no alternative but to quit immediately.
  • (15) TERM — This issues the software termination signal, allowing a program to safely write to configuration files and close.

Beyond these options, there are others like STOP and CONT for pausing and resuming processes, and others for collecting information on a process. These have their various uses, but are primarily for more technical management and troubleshooting of programs and system processes.

One thought on “How to kill a process in OS X

Comments are closed.