我想在eclipse上运行一个c程序,通过JAVA ProcessBuilder,现在我想在某个地方向程序发送终止信号,该程序应该捕获该信号并执行所需的任务然后终止。 现在我知道如何处理信号,但我如何从ProcessBuilder发送信号到我的程序。 任何帮助将不胜感激!
答案 0 :(得分:1)
请参阅此问题: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