- Kill (Unix)
Unixand Unix-like operating systems,
killis a command used to send simple messages to processes running on the system. By default, the message sent is the "termination" signal, which requests that the process exit. But "kill" is something of a misnomer; the signal sent may have nothing to do with process killing. The
killcommand is a
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).
killis always provided as a standalone utility, but most shells have built-in
killcommands that may slightly differ from it.
There are many different signals that can be sent (see signal for a full list), although the signals in which users are generally most interested are
SIGTERMand SIGKILL. The default signal sent is SIGTERM. Programs that handle this signal can do useful cleanup operations (such as saving configuration information to a file) before quitting. However, many programs do not 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
SIGKILLand SIGSTOPcan be "intercepted" by the process, meaning that a special function can be called when the program receives those signals. The two exceptions SIGKILL and SIGSTOP are only seen by the host system's kernel, providing reliable ways of controlling the execution of processes. SIGKILL kills the process, and SIGSTOP pauses it until a SIGCONTis received.
Unix provides security mechanisms to prevent unauthorized users from killing other processes. Essentially, for a process to send a signal to another, the owner of the signaling process must be the same as the owner of the receiving process or be the
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):
kill -TERM 1234
kill -15 1234
The process can be sent a SIGKILL signal in two ways:
kill -KILL 1234
kill -9 1234
Other useful signals include HUP, TRAP, INT and ALRM. A SIGINT signal can be generated very simply by pressing
* System call:
Wikimedia Foundation. 2010.