How to destroy all Processes from a Runtime at once?

↘锁芯ラ 提交于 2019-12-02 17:40:15

问题


So for example:

Runtime rt = Runtime.getRuntime(); creates Runtime rt

Process p1 = rt.exec("C:/Windows/System32/calc.exe"); creates Process p1 on Runtime rt.

Then p1.destroy(); will destroy Process p1.

My question is: If I have more than one Process (e.g. p1, p2, and p3), how do I destroy them all at once, instead of having to destroy them one by one?


回答1:


Keep a List<Process> of all your processes and destroy them in a loop.

List<Process> processes = ...

for(Process p : processes) {
    p.destroy();
}


来源:https://stackoverflow.com/questions/17457057/how-to-destroy-all-processes-from-a-runtime-at-once

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!