Originally Posted By: macnerd10
I believe that it apples to all applications. Quit and force-quit are different in terms of saved work.


Yes, for (almost) all applications they're very different, and I cringe every time I see someone casually suggest kill or killall. It's not just whether the application gets a chance to save its work; if you kill an application while it's in the middle of updating a file, for example in the middle of saving your work, that update is left only half-done, and the file itself is probably corrupted.

Unix has always supported the notion of signals (man 3 signal) as a way to notify an application that something has happened outside. Programs can register to "trap" these signals, and take special action when they occur. A signal that a program does not trap usually causes the program to be aborted; that is, to terminate immediately without finishing whatever it was in the middle of doing. That depends on the signal though; some signals are benign, sent on an FYI basis, and do nothing if not trapped.

The most common signals sent by a user are:

SIGHUP (hangup): originally meant the controlling terminal has hung up. Many programs, by convention, trap SIGHUP and interpret it as "reload preferences, and continue". For example, web servers and other daemons often interpret SIGHUP as a signal that they should check their config files because they've probably changed. Few if any Macintosh programs trap SIGHUP, and will terminate on receiving one.

SIGTERM (terminate): the program should terminate as quickly as possible. This can be trapped, so a program can do cleanup first. If not trapped, it is terminated immediately. Few if any Macintosh applications trap SIGTERM; Unix shells routinely do. Finder, in particular, does not. SIGTERM is the default signal sent by kill, killall, and force quit. kill and killall will send a different signal on request.

SIGKILL (kill): the program terminates instantly. This cannot be trapped. Its main use is to terminate a program that is trapping and ignoring SIGTERM. (For example, the shutdown(8) command sends a SIGTERM to all running applications. If they don't terminate quickly enough, shutdown follows up with SIGKILL.)

SIGINT (interrupt): meant to tell the program to stop what it's doing. For example, by default control-C from a Terminal session sends SIGINT to the current tasks. Your current shell usually traps and ignores this, but child processes also get the SIGINT and usually terminate.


Use of killall makes me especially nervous. Over and above the rudeness of kill is the added fact that its aim is so broad. It kills all processes by the given name, not just the one you think you're killing. For example, killall bash would be frightening, if bash didn't already trap SIGTERM. (You test that at your own risk. I'm afraid to.)