问题
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