Shutdown hook from UNIX Shutdown hook from UNIX unix unix

Shutdown hook from UNIX


You can use code like this on Unix to trap SIGINT (#2) signal:

Signal.handle(new Signal("INT"), new SignalHandler() {      public void handle(Signal sig) {      // Forced exit      System.exit(1);   }});


kill -9 <pid> sends a KILL signal. This signal cannot be intercepted by the program.

If you call kill <pid>, the TERM signal (15) wil be sent. In that case, the JVM will catch the signal and the shutdown hooks will be executed.


This has nothing to do with the signals the JVM is trapping/receiving but everything to do with the terrible shutdown process of Gnome, which apparently needs to be cooperative not to absolutely shit the bed (and the jdk doesn't have the api for this). If you want to see a even worse consequence of this, try to run:

dbus-monitor --profile --session type='method_call',interface='org.gnome.SessionManager'

on a shell, and logout or restart: it will crash gnome-shell and hang the computer until you login on a TTY and order a restart.Maybe kdbus will fix this on this case, maybe not. The only thing i know is that shutdownhooks on a java application that is using AWT (not command line) will NEVER run its shutdownhooks on GNOME3. Actually, the VM will always exit with non-zero code (failure) presumably from native code. At least it doesn't hang, although this makes shutdown hooks quite useless (i've been trying to make a workaround by using dbus-monitor, but as you can see from the example i gave, it's a bit too dangerous too).