The Source for Java Technology Collaboration
User: Password:



Kedar Mhaswade's Blog

February 2007 Archives


kill and kill -9

Posted by km on February 07, 2007 at 10:10 PM | Permalink | Comments (7)

Java provides a way to add a shutdown hook that will be called during the VM's exit sequence and semantics of that are clearly defined in the Javadoc here.

The Javadoc clearly instructs If the virtual machine aborts then no guarantee can be made about whether or not any shutdown hooks will be run.

I was just curious to test this out with GlassFish Application Server on my MacBookPro. When the GlassFish server VM either aborts or shuts down, I observe the following:

signal-id meaning according to manpage observation
Default (no-id, 15) TERM (software termination signal)Shutdown hook called.
1 HUP (hang up)Shutdown hook called, VM exits.
2INT (interrupt) Shutdown hook called, VM exits.
3QUIT (quit)Shutdown hook NOT called, VM continues to run. This is understandable as this should result in VM spitting the thread dump. In other words, this signal is handled at the VM level and Java code does not get a chance to do anything. :)
6ABRT (abort) Shutdown hook NOT called, VM exits.
9KILL (thou shalt die NOW)Shutdown hook NOT called, VM exits.
14ALRM (alarm clock)Shutdown hook NOT called, VM exits.
15 See the default case above. See default case above.





Powered by
Movable Type 3.01D
 Feed java.net RSS Feeds