Saturday 12 July 2014

Reasons not to kill -9 a process in Linux





Its something that is very common and we have all done it in our time. You have a process that is not running the way you want it or maybe it has hung. The solution seems obvious :

$ kill -9 <pid>

I had been told in the past this was a bad idea but why is this not good. There are a few reasons I have found out. When you just kill -9 a process it will not :

- Let its children know that it no longer exists

- Will not shut down its socket connections

- Temp files will not be cleaned up

In general kill -9 should only be used as a last resort as you could at some point end up corrupting an important program e.g. a database.

The recommend procedure to use is :

$ kill -15 <pid>

This allows the target process to try and clean up after itself. If that does not work in order :

$ kill -2 <pid>

$ kill -2 <pid>


And finally ;

$ kill -9 <pid>

Like anything it just takes a bit of getting used to and after 6 months on following this I believe this is a good personal practise to follow.

You can get a full list of the signals with :

 
$ kill -l

No comments:

Post a Comment