列出被 org.apache.commons.exec.ExecuteWatchDog 杀死的进程

问题描述 投票:0回答:1

我有一个基于

org.apache.commons.exec.DefaultExecutor
的基于 Java 的应用程序。 为了确保正在运行的命令在特定超时后被销毁,我将
org.apache.commons.exec.ExecuteWatchDog
附加到它。 我想列出被 WatchDog 破坏的进程,作为故障排除的一部分。我该怎么做?

java
1个回答
0
投票

这通常应该显示进程已被破坏。

import org.apache.commons.exec.ExecuteWatchdog;

public class CustomExecuteWatchdog extends ExecuteWatchdog {

public CustomExecuteWatchdog(long timeout) {
    super(timeout);
}

@Override
public synchronized void destroyProcess() {
    // Before destroying, log the process details
    if (super.killedProcess()) {
        // Assuming you can somehow retrieve process details
        System.out.println("Terminating process: [Process Information Here]");
    }
    super.destroyProcess();
}

}

© www.soinside.com 2019 - 2024. All rights reserved.