Directory

Encyclopedia

NodeWorks
                              ENCYCLOPEDIA

Link Checker

Home
Encyclopedia : K : KI : KIL :

Kill (Unix)

 

Kill (Unix)


In Unix and Unix-like operating systems, kill is a command used to stop programs that are running on the computer, and send other simple messages. It 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). There are many different signals that can be sent, although the signals that users are generally most interested in are SIGTERM and SIGKILL.

The SIGTERM signal is the default signal that is sent. Programs that receive this signal can do useful clean-up operations (such as saving configuration information to a file) before quitting. However, many programs don't 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 can be "intercepted" by the process, meaning that a special function can be called when the program receives those signals. However, the SIGKILL signal is only seen by the host system's kernel, which forcibly stops the process from running.

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. On Linux there are 64 different signals available, and SIGTERM is numbered 15 while SIGKILL is numbered 9.

Here is a complete listing from a Linux system:

[mike@3po][~]$ kill -l 1) SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL 5) SIGTRAP 6) SIGABRT 7) SIGBUS 8) SIGFPE 9) SIGKILL 10) SIGUSR1 11) SIGSEGV 12) SIGUSR2 13) SIGPIPE 14) SIGALRM 15) SIGTERM 17) SIGCHLD 18) SIGCONT 19) SIGSTOP 20) SIGTSTP 21) SIGTTIN 22) SIGTTOU 23) SIGURG 24) SIGXCPU 25) SIGXFSZ 26) SIGVTALRM 27) SIGPROF 28) SIGWINCH 29) SIGIO 30) SIGPWR 31) SIGSYS 35) SIGRTMIN 36) SIGRTMIN+1 37) SIGRTMIN+2 38) SIGRTMIN+3 39) SIGRTMIN+4 40) SIGRTMIN+5 41) SIGRTMIN+6 42) SIGRTMIN+7 43) SIGRTMIN+8 44) SIGRTMIN+9 45) SIGRTMIN+10 46) SIGRTMIN+11 47) SIGRTMIN+12 48) SIGRTMIN+13 49) SIGRTMIN+14 50) SIGRTMAX-14 51) SIGRTMAX-13 52) SIGRTMAX-12 53) SIGRTMAX-11 54) SIGRTMAX-10 55) SIGRTMAX-9 56) SIGRTMAX-8 57) SIGRTMAX-7 58) SIGRTMAX-6 59) SIGRTMAX-5 60) SIGRTMAX-4 61) SIGRTMAX-3 62) SIGRTMAX-2 63) SIGRTMAX-1 64) SIGRTMAX

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

  • kill 1234
  • kill -TERM 1234
  • kill -15 1234

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

  • kill -KILL 1234
  • kill -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.

A related program is killall. On most variations of Unix, 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, the implementation of killall varies on Linux, where an argument is supplied specifying the name of the program to kill. So, rather than manually going through the steps of first running a command like ps to list running processes, then hunting through the output for the specific process intended to be killed, and finally running kill [pid], a single simple command can be used. For instance, to kill the XMMS music player, the user would run the command killall xmms.


NodeWorks boosts web surfing!
Page Returned in 0.067 seconds - HTML Compressed 66.8%

This article is from Wikipedia. All text is available
under the terms of the GNU Free Documentation License.
 GNU Free Documentation License
© 2009 Chamas Enterprises Inc.