The kill command is basically a cli interface to the kill() system call, and it basically sends a signal to a running process. The types of signals are defined on the signal header file (signal.h) under the linux operating system (in Fedora I found it under /usr/include/asm/signal.h instead of /usr/include/linux/signal.h as part of the kernel-headers RPM) or you can list them by running kill -l.
[ansilva@carioca ~]$ 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
16) SIGSTKFLT 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
...
Since I can remember using Linux, I've used the kill command in 3 different ways:
kill SOME_PID
SIGTERM is the default signal if you don't pass the signal number to the command, it will send signal 15, which requests the process to terminate, if the process doesn't terminate, than we usually have to force it with:
kill -9 SOME_PID
The above sends the SIGKILL signal that forces the application to terminate right now.
kill -1 SOME_PID
The -1, aka SIGHUP, is a signal sent to an application when a terminal closes, but if the application does "not require a controlling terminal, such as daemons, would re-purpose SIGHUP as a signal to re-read configuration files, or reinitialize. This convention survives to this day in packages such as Apache and Sendmail." Source: http://en.wikipedia.org/wiki/SIGHUP -- Being that reloading config files was the main reason I've used -1 for.
The interesting part about all this is that one can write an application to intercept theses signals from the kill command when sent to it and do different things with it other than actually 'killing' the process. The only 2 signals that cannot be intercepted are: SIGTERM (15) and SIGKILL (9).
0 comments:
Post a Comment