Original author(s) | AT&T Bell Laboratories |
---|---|
Developer(s) | Variousopen-source andcommercial developers |
Initial release | February 1973; 52 years ago (1973-02) |
Operating system | Unix,Unix-like,Plan 9,Inferno,OS-9,Windows,ReactOS,Singularity,IBM i |
Platform | Cross-platform |
Type | Command |
License | ReactOS:LGPL-2.1-or-later |
Incomputing,kill
is acommand that is used in several popularoperating systems to sendsignals to runningprocesses.
InUnix andUnix-like operating systems,kill
is acommand used to send asignal to a process. By default, the message sent is thetermination signal, which requests that the processexit. Butkill 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 sendssignals to processes orprocess groups on the system, referenced by their numericprocess IDs (PIDs) orprocess group IDs (PGIDs).kill
is always provided as a standalone utility as defined by thePOSIX standard. However, mostshells havebuilt-inkill
commands that may slightly differ from it.[1][2]
There are many different signals that can be sent (seesignal for a full list), although the signals in which users are generally most interested areSIGTERM ("terminate") andSIGKILL ("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 andSIGSTOP ("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'skernel, providing reliable ways of controlling the execution of processes. SIGKILL kills the process, and SIGSTOP pauses it until aSIGCONT ("continue") is received.[3]
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 thesuperuser.
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 aSIGTERM signal in four ways (the process ID is '1234' in this case):
kill1234kill-sTERM1234kill-TERM1234kill-151234
The process can be sent aSIGKILL signal in three ways:
kill-sKILL1234kill-KILL1234kill-91234
Other useful signals include HUP, TRAP, INT,SEGV and ALRM. HUP sends theSIGHUP signal. Some daemons, includingApache andSendmail, re-readconfiguration files upon receiving SIGHUP, so the kill command may be used for this too. ASIGINT signal can be generated very simply by pressingCTRL+C in mostUnix shells. It is also common forCTRL+Z to be mapped toSIGTSTP ("terminal stop"), and forCTRL+\ (backslash) to be mapped toSIGQUIT, which can force a program to do acore dump.
xmms
, the user would run the commandkillall xmms
. This would kill all processes namedxmms
, and is equivalent tokill `pidof xmms`
on systems like Solaris.kill `ps --no-headers -C firefox -o pid`
whereas with pkill, one can simply typepkill firefox
.Thekill
command is also available as ashell builtin in theOS-9 shell. It is used to kill another process by process ID.[4]
Stop the process with the process ID "7":
$ kill 7
taskkill
command onMicrosoft WindowsIn Microsoft's command-line interpreterWindows PowerShell,kill
is a predefinedcommand alias for theStop-Process
cmdlet.
Microsoft Windows XP,Vista and7 include the commandtaskkill
[5] to terminate processes. The usual syntax for this command istaskkill /im "IMAGENAME"
. An "unsupported" version ofkill
was included in several releases of theMicrosoft WindowsResource Kits available for Windows 98.[6]
GNU versions ofkill
have been ported viaCygwin and run inside of the Unix environment subsystem thatMicrosoft Windows Services for UNIX provides (Microsoft acquired Windows Services for Unix wholesale via their purchase of Softway Systems and theirInterix product on September 17, 1999).[7]
taskkill
command onReactOSTheReactOS implementation is based on the Windows variant. It was developed by Andrew Riedi, Andrew Nguyen, and He Yang. It is licensed under theLGPLv2.1 or later.[8]
Find all processes beginning with the letter "p" that were developed by Microsoft and use more than 10 MB of memory and kill them:
PS C:\>psp*|where{$_.Company-like"Microsoft*"-and$_.WorkingSet-gt10MB}|kill-confirmConfirmAre you sure you want to perform this action?Performing operation "Stop-Process" on Target "powershell (6832)".[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"): APS C:\>
Here is a simpler example, which asks the processExplorer.exe to terminate:
PS C:\>taskkill/imexplorer.exe
This example forces the process to terminate:
PS C:\>taskkill/f/imexplorer.exe
Processes can also be killed by theirPID number:
PS C:\>taskkill/pid3476
Singularity shell, the standard shell forMicrosoft Research'smicrokernel operating systemSingularity includes akill
command to terminate background processes.
Stop the process with the name "SampleProcess":
Singularity>kill SampleProcess
Stop the process with the process identifier "42":
Singularity>kill 42
UnderPlan 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 forrc, theshell used by Plan 9, to kill the process.[9]
A similar command provided is calledslay
, which does the same but for processes that refuse to be killed this way.[9]
For example, to kill all instances oftroff, one types:
kill troff | rc
Thekill command has also been ported to theIBM i operating system.[10]
kill
– Shell and Utilities Reference,The Single UNIX Specification, Version 4 fromThe Open Groupkill
– System Interfaces Reference,The Single UNIX Specification, Version 4 fromThe Open Groupkill(1)
– Plan 9 Programmer's Manual, Volume 1kill(1)
– Inferno General commandsManualkill(1)
– Linux User CommandsManual