- Kill (Unix)
In
Unix andUnix-like operating system s,kill
is 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. Thekill
command is awrapper around thekill()
system call , which sends signals to processes orprocess group s on the system, referenced by their numericprocess ID s (PIDs) or process group IDs (PGIDs).kill
is always provided as a standalone utility, but most shells have built-inkill
commands 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
SIGTERM andSIGKILL . 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
SIGKILL andSIGSTOP can 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 aSIGCONT is 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
superuser .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.
Examples
A process can be sent a SIGTERM signal in three ways (the process ID is '1234' in this case):
*
kill 1234
*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.