https://www.cnblogs.com/qianjinyan/p/10772540.html
taskkill是Windows命令行里終止指定程序“進(jìn)程”的命令。
/f 表示強(qiáng)制終止
/im 表示指定的進(jìn)程名稱,例如“explor.exe"
/pid 表示指定的進(jìn)程ID進(jìn)程號(hào)
taskkill /f /im javaw.exe
taskkill /f /pid 3352
參考jenkins的部分代碼,發(fā)現(xiàn)其使用了如下的工具包,經(jīng)驗(yàn)證該工具獲取的pid和windows任務(wù)管理器看到的也不一樣,但是通過(guò)其關(guān)閉方法卻可以關(guān)閉進(jìn)程,還沒(méi)弄清楚這個(gè)pid和任務(wù)管理器里面看到的pid有什么不同。
<dependency>
<groupId>org.jvnet.winp</groupId>
<artifactId>winp</artifactId>
<version>1.28</version>
</dependency>
if (File.pathSeparatorChar == ';' || OSUtil.osEnum == OSEnum.Windows ) {
WindowsProcessUtil.killRecursively(process, runJobId);
}
public static void killRecursively(Process process,Long runJobId) {
String logKey = "killAllChildProcess,runJobId=" + runJobId + ",";
WinProcess winProcess = new WinProcess(process);
int rootPid = winProcess.getPid();
LogUtil.info(logKey + "rootPid=" + rootPid);
if (rootPid < 1) {
LogUtil.error(logKey + "rootPid=" + rootPid + ",should not less than 1 ");
return;
}
winProcess.killRecursively();
}