2

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?

fluter
  • 13,238
  • 8
  • 62
  • 100
Shubham Chaurasia
  • 2,472
  • 2
  • 15
  • 22
  • Why do you want to do that? I suspect it's not possible to do properly - SIGKILL, for example, can't simply be caught and ignored - it *will* cause the process to terminate unless its in uninterruptable sleep, either way the process isn't going to do anything useful after receiving a SIGKILL. – sisyphus Apr 26 '16 at 08:18
  • fix wordings, markers – fluter Apr 26 '16 at 08:40
  • Duplicate; linking to my answer there https://stackoverflow.com/a/67852569/448779 – foo Dec 27 '22 at 18:57

1 Answers1

1

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 &

the8472
  • 40,999
  • 5
  • 70
  • 122