In my Java application, I want to capture SIGINT, do some preprocessing, and then start the default behavior (process termination). I would think I could do something like this:
Signal.handle(new Signal("INT"), new SignalHandler() { @Override public void handle(Signal signal) {
However, when I send to SIGINT in this application, I get SEGV :
#
It seems that SignalHandler.SIG_DFL not intended to be called directly (even from another signal processing code). So how can I manually start it?
Alternatively, how can I manually reproduce the behavior of SIG_DFL ? It seems equivalent:
System.exit(signal.getNumber() + 128)
but I do not see any documentation on this.
Another way to talk about my question:
In practice * is there a difference between the two code blocks?
A)
Signal.handle(new Signal("INT"), SignalHandler.SIG_DFL);
IN)
Signal.handle(new Signal("INT"), new SignalHandler() { @Override public void handle(Signal signal) { System.exit(signal.getNumber() + 128) }});
* I know that undocumented behavior can change at any time, but it is unlikely that the behavior of the JVM output will change in the middle of the version. The answer, which simply details what is happening now, is acceptable in practice.