kill (Unix)

from Wikipedia, the free encyclopedia

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. killkill()

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 killcommand 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 $pidprovoked 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 killallautomatically 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 xmmscalled via , the user enters killall xmms. This will kill all processes with the name xmms. In addition, there is usually an additional one killall5that behaves similar to the killall from SystemV / Solaris.

pkill

pkillterminates 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

  1. see Signal (Unix) for a list of common signals

Web links