Quote:
Originally Posted by
newbie_01
I think I should start adding that in all of the scripts especially for SIGKILL=9 when we have to do a kill -9.
Expanding on what Don Cragun has already explained: The difference between "9" and all other signals a process can get is that "9" (like in
kill -9) is not handled by the process itself. Itis handled by the system (that is: a part of the kernel).
When you issue the command
kill -n <PID> (for
n being some number - see
kill -l for a list of all legal values) this generates a "signal" which is then passed to the process and handled by it. In principle a process can react however it wants (or even not at all) to a specific signal but there are conventions and therefore expected reactions of a process to a certain signal. i.e.
kill -1 usually causes a process to re-read its configuration file(s) and then resume operation using this new configuration.
The ultimate signal you can send to a process is "15" which means "terminate immediately". A well-behaved process will then terminate, no matter what it is doing. Still, "terminating" here means not just "exit" but to perform every cleanup possible: it there are temporary files open, then close them and remove them, if there are network connections open close them and free up the sockets, etc..
This is the main difference between signal 15 and 9: with 9 the process will not be notified but immediately (and in the most brutal way possible) removed by the OS. It will simply have no time to clean up, in fact it isn't even aware of it being killed.
Therefore, when you want to stop a process, always try
kill -15 at least once (better: two to three times) and only if the process is proven not to be able to terminate itsself any more try a
kill -9 - but ONLY then. Your system will remain much more stable because processes will have the chance to clean up (and well-behaved UNIX processes do that!).
I hope this helps.
bakunin