Nov 11
When should I use kill -9 ?
Posted by James Netherton | Wednesday 11 November 2009 21:05 PM | In Linux
When should I use kill -9 ?
The answer is – Rarely! Or at least only in exceptional circumstances…..
The -9 signal is the KILL signal which forces a process to immediately terminate. Many processes perform clean up operations when they terminate, perhaps to close open files, remove temporary files & directories etc. Using the -9 signal prevents a process from executing any of its shut down hooks and could potentially leave your application / system in an inconsistent state.
If a process needs to be killed, it’s often better to use the kill command on its own or use kill -15 (-15 is usually the default signal) which sends the TERM signal to the process. The TERM signal tells a process to gracefully terminate which means it will be able to run any shut down hooks and thus leave your system in a potentially nicer state than it would have been if you’d have used kill -9.
I see kill -9 used in so many inappropriate circumstances, such as in scripts to stop some service or application. Kill -9 should never be used in such cases.
The *nix man pages have a good overview of the kill command. You can also get a list of all kill signals by executing kill -l.