java - 优雅地杀死 Apache Commons Exec 进程

标签 java unix apache-commons apache-commons-exec

我正在我的 Java 程序(在 Linux 上)中启动一个外部进程,我需要能够向它发送 SIGTERM 信号而不是 exec.getWatchdog().destroyProcess() 的 SIGKILL发送。有没有一种方法可以更优雅地停止以 commons-exec 启动的 unix 进程?或者我可以获取 PID 以便我可以自己运行适当的 kill 命令吗?

最佳答案

ExecuteWatchdog 类有杀死进程的方法。

因此,您可以只创建一个超时时间较长的看门狗,并在必要时使用它来终止进程,即

executor.getWatchdog().destroyProcess();

关于java - 优雅地杀死 Apache Commons Exec 进程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5174426/

相关文章:

java - Swing : Can children exceed the bounds of their parent?

Java Jersey / jackson : return dynamic JSON properties

java - OSGI - 缺少导入的包=org.apache.commons.collections

Apache Math.Commons 库中的 Java-DerivativeStructure

java - Spring Security Role Hierarchy 无法使用 Java Config

我们可以用阻塞套接字制作一个非阻塞服务器吗?

c++ - 在类似于 unix shell 脚本的 c++ 中调用后台函数

linux - 建议 : USB Monitoring Programming

java - Apache commons-validator 不验证 gmail

Java Persistence API 读取 unicode JSON 列