<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>

[{'answer_id': 40390, 'author': 'toolkit', 'author_id': 3295, 'author_profile': 'https://Stackoverflow.com/users/3295', 'pm_score': 2, 'selected': False, 'text': '<p>Perhaps <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Runtime.html#addShutdownHook%28java.lang.Thread%29" rel="nofollow noreferrer">Runtime#addShutdownHook</a> ?</p>\n'}, {'answer_id': 41157, 'author': 'Will', 'author_id': 816, 'author_profile': 'https://Stackoverflow.com/users/816', 'pm_score': 5, 'selected': True, 'text': '<p>The JVM responds to signals on its own. Some will cause the JVM to shutdown gracefully, which includes running shutdown hooks. Other signals will cause the JVM to abort without running shutdown hooks.</p>\n\n<p>Shutdown hooks are added using <a href="http://java.sun.com/javase/6/docs/api/java/lang/Runtime.html#addShutdownHook%28java.lang.Thread%29" rel="noreferrer">Runtime.addShutdownHook(Thread)</a>.</p>\n\n<p>I don\'t think the JDK provides an official way to handle signals within your Java application. However, I did find <a href="http://www.ibm.com/developerworks/java/library/i-signalhandling/" rel="noreferrer">this IBM article</a>, which describes using some undocumented <code>sun.misc.Signal</code> class to do exactly that. The article dates from 2002 and uses JDK 1.3.1, but I\'ve confirmed that the <code>sun.misc.Signal</code> class still exists in JDK 1.6.0.</p>\n'}]
['https://Stackoverflow.com/questions/40376', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/4308/']