Search code examples
javalinuxprocessjvmshutdown

Regarding JVM signal handling


I want to disable signals like SIGINT, which is sent by pressing CTRL_C, and also other signals which will terminates JVM. I read about -Xrs option here

http://docs.oracle.com/javase/7/docs/technotes/tools/windows/java.html?cm_mc_uid=30731201786714525992590&cm_mc_sid_50200000=1461656557

But it seems to have no effect on JVM/process termination. I launched the program jar like java -Xrs -jar avoid-signals.jar.
I am on linux. Any Suggestions?


Solution

  • The documentation for Xrs says

    Reduces use of operating-system signals by the Java VM.

    That means the JVM only installs fewer of its own signal handlers. Fewer signal handlers simply mean that more signals are handled through their default action. Which in many cases results in process termination.

    Signals can either be suppressed through a signal mask, processed through a signal handler or various other means.

    Currently the JDK offers no public APIs, but you can either use internal, unsupported ones (sun.misc.SignalHandler) or jnr-posix.

    Or if you mostly care about Ctrl+C and other keystrokes and not really the signals themselves you can detach the java process from the console via nohup java -jar ... > /dev/null &