<p>Is it possible to handle POSIX signals within the Java Virtual Machine?</p>

<p>At least <a href="http://en.wikipedia.org/wiki/SIGINT_(POSIX)" rel="noreferrer">SIGINT</a> and <a href="http://en.wikipedia.org/wiki/SIGKILL" rel="noreferrer">SIGKILL</a> should be quite platform independent.</p>

Perhaps
Runtime#addShutdownHook
?