我想在 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/