views:

83

answers:

4

Which problem can cause kill -9 in production application (in linux to be exact)?

I have application which do some periodical work, stopping these takes long time, and I don't care if some jobs will be aborted - work can be finished by new processes. So can I use kill -9 just to stop it immediately or this can cause serious OS problems?

For example, Unicorn, uses it as normal working procedure:

When your application goes awry, a BOFH can just "kill -9" the runaway worker process without worrying about tearing all clients down, just one.

But this article claims:

The -9 (or KILL) argument to kill(1) should never be used on Unix systems

PS: I understand that kill -9 cannot be handled by application, but I know that for may application it doesnt cause any problems, I just intrested can it cause some problems on OS level? shared memory segments active, lingering sockets sounds dangerous to me.

+3  A: 

kill -9 doesn't give an application a chance to shut down cleanly.

Normally an application can catch a SIGINT/SIGTERM and shut down cleanly (close files, save data etc.). An application can't catch a SIGKILL (which occurs with a kill -9) and so it can't do any of this (optional) cleanup.

A better approach is to use a standard kill, and if the application remains unresponsive, then use kill -9.

Brian Agnew
A: 

The KILL signal cannot be caught by the application. If the application is in the middle of writing some complex data structure to disk when you kill it, the structure may be only half-written, resulting in a corrupted data file. it is usually best to implement some other signal such as USER1 as the "stop" signal, as this can be caught and allows the application to shut down in a controlled manner.

anon
+2  A: 

kill -9 won't cause any "serious OS problems". But the process will stop immediately, which means it might leave data in an odd state.

Matt Curtis
+1  A: 

It depends what kind of application it is.

Something like a database may either lose data (if it does not write all its data to a persistent transaction log at once), or take longer to start up next time, or both.

Although Crash-only is a good principle, few application currently conform to it.

For example, the mysql database is not "crash only" and killing it with a kill -9 will result in either significantly longer startup time (than a clean shutdown), data loss, or both, depending on the settings (and to some extent, luck).

On the other hand, Cassandra actually encourages the use of kill -9 as a shutdown mechanism; it supports nothing else.

MarkR