kill (Unix)
kill ( engl. kill ) is a Unix command and eponymous system call to below the operating system running processes signals to send. By default, the SIGTERM signal is sent with the UNIX kill command , which requests the relevant process to terminate. Since the termination of processes is only one use case of the program or system call , the term kill is misleading, since it is more generally about interprocess communication . The name comes from Unix versions before Unix V4, for which there was no signal parameter.
kill
kill()
functionality
The Unix command kill is a wrapper around the operating system call kill()
. Although it is available as a stand-alone application on every Unix derivative (usually below /bin/kill
), all modern Unix shells have a built-in kill
command due to its trivial implementation .
Many different signals can be sent with kill , but the most commonly used signals are SIGTERM and SIGKILL . If no parameters are specified, kill SIGTERM sends. The receiving programs can intercept this signal and carry out necessary work steps before exiting, e.g. B. save open files . SIGKILL is used to end a process that does not terminate despite receiving a SIGTERM signal. In addition to the SIGSTOP signal , SIGKILL is therefore the only signal that cannot be "intercepted" by the program in order to perform program-specific actions. The two signals SIGKILL and SIGSTOP are therefore only "seen" by the kernel and therefore always offer reliable ways to control a process. While SIGKILL instructs the kernel to "kill" the process, the kernel pauses it with SIGSTOP until the SIGCONT signal is received.
Not every call to kill is used to kill a process. So there are B. the program dd with the signal SIGUSR1 the current processing status of a copying process on the standard error output, this can be kill -USR1 $pid
provoked with .
With Unix as a classic multi-user system, each process has an owner ( UID ). Each process may only send one signal to a process that belongs to the same owner. This means that each user is only allowed to terminate his own processes. The exception is the superuser , who is allowed to send signals to every process on the system.
use
The syntax of the Unix command is
kill Parameter eine oder mehrere Prozess-IDs
The desired signal can be specified as an optional parameter, in the form where SIGNAL corresponds either to the signal number or the name.
-SIGNAL
For example, to send the SIGTERM signal to a fictitious process with ID 4711 , there are three possible call variants:
kill 4711
kill -TERM 4711
kill -15 4711
The call is made analogously with other signals, e.g. B. SIGKILL:
kill -KILL 4711
kill -9 4711
Alternatives
Keyboard shortcuts
Modern Unix shells intercept key combinations in order to send them to running foreground processes. In order to terminate a program, it is usually sufficient under Unix to enter Strgand C, which sends a SIGINT signal to the process . It is usually sent by entering Strg+ Z SIGTSTP , and also with Strg+ \ SIGQUIT , which asks a program to output a memory dump (core dump).
killall
Some Unix derivatives, including Solaris , call the Unix command killall
automatically when the system shuts down. It behaves like kill , only a signal is sent not just to a single process, but to all processes on the system.
On other Unix derivatives, etc. a. IRIX , Linux and FreeBSD , however, use the killall command to kill a process based on its name. For example , to end XMMS , a media player that was xmms
called via , the user enters killall xmms
. This will kill all processes with the name xmms
. In addition, there is usually an additional one killall5
that behaves similar to the killall from SystemV / Solaris.
pkill
pkill
terminates processes based on part of their name. The command was introduced in Solaris 7 and has since been implemented in Linux and OpenBSD . pkill makes it easier to kill processes based on their name than is possible with killall if you do not know their exact name.
For example, in order to end the processes belonging to the Firefox web browser without using pkill and pgrep, one would have to write a line like , whereas with pkill the input of the purpose would already be fulfilled.
kill $(ps ax | awk '$5~/firefox/{print $1}')
pkill firefox
See also
- xkill , for terminating X window programs
Individual evidence
- ↑ see Signal (Unix) for a list of common signals
Web links
-
kill
: terminate a process - Open Group Base Specification -
kill()
: send a signal to a process or a group of processes - Open Group Base Specification -
kill(2)
: send signal to a process - OpenBSD System Calls Manual -
killall(1)
: kill processes by name - Debian GNU / Linux executables or shell commands man page -
killall5(1)
: send a signal to all processes ( System V ) - Debian GNU / Linux Executable programs or shell commands man page -
pgrep(1)
,pkill(1)
: look up or signal processes based on name and other attributes - Debian GNU / Linux Executables or shell commands man page -
xkill(1)
: kill a client by its X resource - Debian GNU / Linux executables or shell commands manual page