我正在做一些监控线程。已将进程ID(PID)存储在hash map
中。在线程中,我正在检索那些PID,在某些情况下,我想终止特定的PID。我在web上搜索了windows
环境,kill命令是:Runtime.getRuntime().exec("taskkill /F /PID "+PID_id);
,其中PID是我从map获得的PID。我想知道,我怎样才能在ubuntu
(Linux
)环境中做这样的事情。
最佳答案
Process process = Runtime.getRuntime().exec("kill -9 "+PID_id);
int retCode = process.waitFor();