如何一次从运行时销毁所有进程? [英] How to destroy all Processes from a Runtime at once?

查看:54
本文介绍了如何一次从运行时销毁所有进程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如:

Runtime rt = Runtime.getRuntime(); 创建 Runtime rt

Process p1 = rt.exec("C:/Windows/System32/calc.exe");Runtime rt 上创建 Process p1>.

然后 p1.destroy(); 将销毁 Process p1.

我的问题是:如果我有多个 Process(例如 p1p2p3),如何一次性全部销毁,而不是一个一个销毁?

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?

推荐答案

保留所有进程的 List 并在循环中销毁它们.

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

List<Process> processes = ...

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

这篇关于如何一次从运行时销毁所有进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆