Kill (command)

Revision as of 03:32, 1 April 2025 by imported>Grayfell (Reverted 1 edit by 24.237.159.218 (talk) to last revision by 98.115.164.53)
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

Template:Short description Template:Lowercase Template:For {{#invoke:Infobox|infobox}}Template:Template other{{#invoke:Check for unknown parameters | check | showblankpositional=1 | unknown = Template:Main other | preview = Page using Template:Infobox software with unknown parameter "_VALUE_"|ignoreblank=y | AsOf | author | background | bodystyle | caption | collapsetext | collapsible | developer | discontinued | engine | engines | genre | included with | language | language count | language footnote | latest preview date | latest preview version | latest release date | latest release version | latest_preview_date | latest_preview_version | latest_release_date | latest_release_version | licence | license | logo | logo alt | logo caption | logo upright | logo size | logo title | logo_alt | logo_caption | logo_upright | logo_size | logo_title | middleware | module | name | operating system | operating_system | other_names | platform | programming language | programming_language | released | replaced_by | replaces | repo | screenshot | screenshot alt | screenshot upright | screenshot size | screenshot title | screenshot_alt | screenshot_upright | screenshot_size | screenshot_title | service_name | size | standard | title | ver layout | website | qid }}Template:Main other In computing, kill is a command that is used in several popular operating systems to send signals to running processes.

ImplementationsEdit

Unix and Unix-likeEdit

In Unix and Unix-like operating systems, kill 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 kill command 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). kill is always provided as a standalone utility as defined by the POSIX standard. However, most shells have built-in kill commands that may slightly differ from it.<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref><ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref>

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.<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref>

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.

ExamplesEdit

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

<syntaxhighlight lang="bash"> kill 1234 kill -s TERM 1234 kill -TERM 1234 kill -15 1234 </syntaxhighlight>

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

<syntaxhighlight lang="bash"> kill -s KILL 1234 kill -KILL 1234 kill -9 1234 </syntaxhighlight>

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 [[Control-C|Template:Keypress]] in most Unix shells. It is also common for [[Control-Z|Template:Keypress]] to be mapped to SIGTSTP ("terminal stop"), and for [[Control-\|Template:Keypress]] (backslash) to be mapped to SIGQUIT, which can force a program to do a core dump.

Related programsEdit

  • killall - on some variations of Unix, such as Solaris, 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, on others such as IRIX, Linux, and FreeBSD, an argument is supplied specifying the name of the process (or processes) 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. This would kill all processes named xmms, and is equivalent to kill `pidof xmms` on systems like Solaris.
  • pkill - signals processes based on name and other attributes. It was introduced in Solaris 7 and has since been reimplemented for Linux, NetBSD and OpenBSD. pkill makes killing processes based on their name much more convenient: e.g. to kill a process named firefox without pkill (and without pgrep), one would have to type kill `ps --no-headers -C firefox -o pid` whereas with pkill, one can simply type pkill firefox.
  • xkill - if called without any parameters, the mouse cursor changes from an arrow to an "x" icon, and the user can click on a window to force the X server to close the connection with the client owning the window. This often causes the process to terminate when it detects that its connection to the X server has been closed.

Microware OS-9Edit

The kill command is also available as a shell builtin in the OS-9 shell. It is used to kill another process by process ID.<ref>Template:Cite book</ref>

Stop the process with the process ID "7":

<syntaxhighlight lang="text"> $ kill 7 </syntaxhighlight>

Microsoft Windows and ReactOSEdit

File:Taskkill.jpg
The <syntaxhighlight lang="text" class="" style="" inline="1">taskkill</syntaxhighlight> command on Microsoft Windows

In Microsoft's command-line interpreter Windows PowerShell, kill is a predefined command alias for the Stop-Process cmdlet.

Microsoft Windows XP, Vista and 7 include the command taskkill<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref> to terminate processes. The usual syntax for this command is taskkill /im "IMAGENAME". An "unsupported" version of kill was included in several releases of the Microsoft Windows Resource Kits available for Windows 98.<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref>

GNU versions of kill 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).<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref>

File:ReactOS-0.4.13 taskkill command 667x434.png
The <syntaxhighlight lang="text" class="" style="" inline="1">taskkill</syntaxhighlight> command on ReactOS

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.<ref name="reactos">reactos/taskkill.c at master · reactos/reactos · GitHub</ref>

ExamplesEdit

Find all processes beginning with the letter "p" that were developed by Microsoft and use more than 10 MB of memory and kill them:

<syntaxhighlight lang="ps1con"> PS C:\> ps p* | where { $_.Company -like "Microsoft*" -and $_.WorkingSet -gt 10MB } | kill -confirm

Confirm Are 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"): A PS C:\> </syntaxhighlight>

Here is a simpler example, which asks the process Explorer.exe to terminate: <syntaxhighlight lang="ps1con">PS C:\> taskkill /im explorer.exe</syntaxhighlight> This example forces the process to terminate: <syntaxhighlight lang="ps1con">PS C:\> taskkill /f /im explorer.exe</syntaxhighlight> Processes can also be killed by their PID number: <syntaxhighlight lang="ps1con">PS C:\> taskkill /pid 3476</syntaxhighlight>

Microsoft SingularityEdit

Singularity shell, the standard shell for Microsoft Research's microkernel operating system Singularity includes a kill command to terminate background processes.

ExamplesEdit

Stop the process with the name "SampleProcess":

<syntaxhighlight lang="text"> Singularity>kill SampleProcess </syntaxhighlight>

Stop the process with the process identifier "42":

<syntaxhighlight lang="text"> Singularity>kill 42 </syntaxhighlight>

Plan 9 from Bell LabsEdit

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.<ref name="plan9wiki">{{#invoke:citation/CS1|citation |CitationClass=web }}</ref>

A similar command provided is called slay, which does the same but for processes that refuse to be killed this way.<ref name="plan9wiki" />

ExamplesEdit

For example, to kill all instances of troff, one types:

kill troff | rc

OthersEdit

The Template:Mono command has also been ported to the IBM i operating system.<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref>

See alsoEdit

ReferencesEdit

Template:Reflist

Further readingEdit

External linksEdit

Template:Sister project

Template:Unix commands Template:Plan 9 commands Template:Windows commands