tags:

views:

27

answers:

1

I'm using a Java wrapper for a native shared library on Unix (JRI). The native library (a C based REPL implementation for R) handles SIGINT internally. When using the Java wrapper, the Java application quits when I send a SIGINT to the process using:

kill -SIGINT pid

I'd prefer for the SIGINT to be entirely handled by the native library internally.

Is there an easy way to make Java completely ignore a SIGINT but still have the native library receive it?

Addition:

Preferably this would work on Unix and OSX.

+3  A: 

There is no standard API for it, but if you are using the Sun JDK, you can use sun.misc.Signal and sun.misc.SignalHandler. Example from the docs:

SignalHandler handler = new SignalHandler () {
    public void handle(Signal sig) {
        ... // handle SIGINT
    }
};
Signal.handle(new Signal("INT"), handler);
Wouter Coekaerts
Know any way to get this to work on OSX? I don't seem to have access to sun.misc.
Tristan
This should work fine on all operating systems, that is not the problem.If you don't have those, maybe you are using a different JDK? See the output of "java -version"
Wouter Coekaerts
Great, it works. It was just Eclipse giving an error.
Tristan