kill (Unix)
From Wikipedia, the free encyclopedia
In Unix and Unix-like operating systems, kill is a command used to send simple messages to processes running on the system. 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, but most shells have built-in kill 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 and SIGKILL. 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 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 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. It is important to note that the specific mapping between numbers and signals can vary between Unix implementations. SIGTERM is often numbered 15 while SIGKILL is often numbered 9.
Contents |
[edit] Examples
A process can be sent a SIGTERM signal in three ways (the process ID is '1234' in this case):
kill 1234kill -TERM 1234kill -15 1234
The process can be sent a SIGKILL signal in two ways:
kill -KILL 1234kill -9 1234
Other useful signals include HUP, TRAP, INT and ALRM. A SIGINT signal can be generated very simply by pressing CTRL+C in most Unix shells. It is also common for CTRL+Z to be mapped to SIGTSTP, and for CTRL+\ (backslash) to be mapped to SIGQUIT, which can force a program to do a core dump.
[edit] Related programs
- 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 commandkillall xmms. This would kill all processes namedxmms. - pkill - signals processes based on name and other attributes. It was introduced in Solaris 7 and has since been reimplemented for Linux 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 -ax | grep firefox | grep -v grep | awk '{print $1}'`whereas with pkill, one can simply typepkill firefox.
[edit] Windows
Microsoft Windows XP and Microsoft Windows Vista include the command taskkill[1] to terminate processes. An "unsupported" version of Kill was included in several releases of the Microsoft Windows Resource Kits (aka "RezKits") available for Windows NT 3.x, NT 4.0, Windows 2000 and Microsoft Windows Server 2003, the most efficacious of these being Version 3.5 of Kill, Copyright (C) 1994 Microsoft Corp. GNU versions of Kill have been ported via Cygwin and run inside of the unix os layer that Microsoft Windows Services for UNIX[2] provides (Microsoft acquired Windows Services for Unix wholesale via their purchase of Softway Systems and their Interix product in September 17, 1999).
Although Kill adds much-needed granularity to the management of individual threads and executables in the win32 world, virtually none of the variants of Kill (either ported from the POSIX world, emulated or scratch-built binaries) retain the full functionality and ultimate control over running Windows processes as do the Unix counterparts.
[edit] Plan 9 from Bell Labs
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. For example, to kill all instances of troff, one types
kill troff | rc
A similar command provided is called slay, which does the same but for processes that refuse to be killed this way.
[edit] See also
[edit] References
[edit] External links
- Command: : terminate a process – Linux man page
- System call: : send signal to a process – Linux man page
|
||||||||||||||||||||||||||

