In computing, <code>kill</code> is a command that is used in several popular operating systems to send signals to running processes.
In Unix and Unix-like operating systems, <code>kill</code> is a command used to send a signal to a process. 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 <code>kill</code> command is a wrapper around the <code>kill()</code> 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). <code>kill</code> is always provided as a standalone utility as defined by the POSIX standard. However, most shells have built-in <code>kill</code> 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 ("terminate") and SIGKILL ("kill"). 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 and SIGSTOP ("stop") 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 a SIGCONT ("continue") 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. 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 four ways (the process ID is '1234' in this case):
The process can be sent a SIGKILL signal in three ways:
Other useful signals include HUP, TRAP, INT, SEGV and ALRM. HUP sends the SIGHUP signal. Some daemons, including Apache and Sendmail, re-read configuration files upon receiving SIGHUP, so the kill command may be used for this too. A SIGINT signal can be generated very simply by pressing in most Unix shells. It is also common for to be mapped to SIGTSTP ("terminal stop"), and for (backslash) to be mapped to SIGQUIT, which can force a program to do a core dump.
The <code>kill</code> command is also available as a shell builtin in the OS-9 shell. It is used to kill another process by process ID.
Stop the process with the process ID "7":
In Microsoft's command-line interpreter Windows PowerShell, <code>kill</code> is a predefined command alias for the <code>Stop-Process</code> cmdlet.
Microsoft Windows XP, Vista and 7 include the command <code>taskkill</code> to terminate processes. The usual syntax for this command is <code>taskkill /im "IMAGENAME"</code>. An "unsupported" version of <code>kill</code> was included in several releases of the Microsoft Windows Resource Kits available for Windows 98.
GNU versions of <code>kill</code> have been ported via Cygwin and run inside of the Unix environment subsystem that Microsoft Windows Services for UNIX provides (Microsoft acquired Windows Services for Unix wholesale via their purchase of Softway Systems and their Interix product on September 17, 1999).
The ReactOS implementation is based on the Windows variant. It was developed by Andrew Riedi, Andrew Nguyen, and He Yang. It is licensed under the LGPLv2.1 or later.
Find all processes beginning with the letter "p" that were developed by Microsoft and use more than 10 MB of memory and kill them:
Here is a simpler example, which asks the process Explorer.exe to terminate:
This example forces the process to terminate:
Processes can also be killed by their PID number:
Singularity shell, the standard shell for Microsoft Research's microkernel operating system Singularity includes a <code>kill</code> command to terminate background processes.
Stop the process with the name "SampleProcess":
Stop the process with the process identifier "42":
Under Plan 9 from Bell Labs, the kill program does not actually perform this termination, nor does it take process IDs. Rather, it takes the actual names of processes and outputs the commands for rc, the shell used by Plan 9, to kill the process.
A similar command provided is called <code>slay</code>, which does the same but for processes that refuse to be killed this way.
For example, to kill all instances of troff, one types:
kill troff | rc
The command has also been ported to the IBM i operating system.