Kill (Unix)

The title of this article is incorrect because of technical limitations. The correct title is kill.

In Unix and Unix-like operating systems, kill is a command used to stop programs that are running on the computer, and send other simple messages. It is a wrapper around the kill() system call, which sends signals to processes or process groups on the system, referenced by their numeric process IDs (PIDs) or process group IDs (PGIDs). There are many different signals that can be sent, although the signals that users are generally most interested in are SIGTERM and SIGKILL.

The SIGTERM signal is the default signal that is sent. Programs that receive this signal can do useful clean-up operations (such as saving configuration information to a file) before quitting. However, many programs don't implement a special handler for this signal, and so a default signal handler is called instead. Other times, even a process that has a special handler has gone awry in a way that prevents it from properly handling the signal.

All signals except for SIGKILL can be "intercepted" by the process, meaning that a special function can be called when the program receives those signals. However, the SIGKILL signal is only seen by the host system's kernel, which forcibly stops the process from running.

The available signals all have different names, and are mapped to certain numbers. It is important to note that the specific mapping between numbers and signals can vary between Unix implementations. SIGTERM is often numbered 15 while SIGKILL is often numbered 9.

A process can be sent a SIGTERM signal in three ways (the process ID is '1234' in this case):

The process can be sent a SIGKILL signal in two ways:

Other useful signals include HUP, TRAP, INT and ALRM. A SIGINT signal can be generated very simply by pressing CTRL+C in most Unix shells. It is also common for CTRL+Z to be mapped to SIGTSTP, and for CTRL+\ (backslash) to be mapped to SIGQUIT, which can force a program to do a core dump.

A related program is killall. On most variations of Unix, this utility is automatically invoked when the system is going through a shutdown. It behaves much like the kill command above, but instead of sending a signal to an individual process, the signal is sent to all processes on the system. However, the implementation of killall varies on Linux, where an argument is supplied specifying the name of the program to kill. For instance, to kill a process such as an instance of the XMMS music player invoked by xmms, the user would run the command killall xmms.

See also: Kill (Unix), Computer process, Core dump, Kernel, Linux, Operating system, Process ID, Shutdown