java - 在通过 ProcessBuilder 运行的 C 程序中捕获信号

标签 java c++ signals exec processbuilder

我想在 eclipse 上通过 JAVA ProcessBuilder 运行一个 c 程序,现在在某个地方我想向该程序发送终止信号,该程序应该捕获该信号并执行所需的任务然后终止。 现在我知道如何处理信号,但如何将信号从 ProcessBuilder 发送到我的程序。 任何帮助将不胜感激!

最佳答案

看到这个问题:How to send SIGINT signal from Java to an external process?

Can you send `kill -SIGINT <pid>` to the process (given that you know the process ID):

    Runtime.getRuntime().exec("kill -SIGINT 12345");

Of course, that would make for a platform-dependent solution... Potentially, you'll be able to use this tool, although it is in "sandbox mode". But it might give you an idea:

http://commons.apache.org/sandbox/runtime/

See also this related question here:

https://stackoverflow.com/questions/2950338/how-can-i-kill-a-linux-process-in-java-with-sigkill-process-destroy-does-sigte

关于java - 在通过 ProcessBuilder 运行的 C 程序中捕获信号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20763611/

相关文章:

java - 如何使选定的组合框值显示不同的文本?

c++ - 在 unsigned int 中使用第一位作为标志

C++ 枚举类 : Cast to non existing entry

java - Alljoyn 框架 - Java - 信号。 BUS_NO_SUCH_INTERFACE

matlab - 在 Simulink 中以编程方式标记信号

java - 如何打开光驱java

java - Cobertura 检查 Travis CI 失败

Java - 将复杂的 List#toString 转换为列表

c++ - 基本菜单驱动程序 C++,无限循环

Swift,在 GCD 中,SIGUSR1 不起作用