本文介绍了忽略Java中的SIGINT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Unix上的本地共享库中使用Java包装器( JRI ).本机库(R的基于C的REPL实现)在内部处理SIGINT.使用Java包装程序时,当我使用以下命令将SIGINT发送到进程时,Java应用程序退出:

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

kill -SIGINT pid

我希望SIGINT完全由本地库在内部处理.

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

是否有一种简单的方法可以使Java完全忽略SIGINT,但仍然让本机库接收它?

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

添加:

最好在Unix和OSX上工作.

Preferably this would work on Unix and OSX.

推荐答案

没有标准的API,但是,如果您使用的是Sun JDK,则可以使用 sun.misc.Signal sun.misc.SignalHandler .文档中的示例:

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);

这篇关于忽略Java中的SIGINT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 02:41
查看更多