该代码列出 Windows 下当前运行的所有进程
import java.io.*;
public class ListProcess {
public static void main(String[] args) throws IOException
{
Runtime runtime = Runtime.getRuntime();
String cmds[] = {"cmd", "/c", "tasklist"};
Process proc = runtime.exec(cmds);
InputStream inputstream = proc.getInputStream();
InputStreamReader inputstreamreader = new InputStreamReader(inputstream);
BufferedReader bufferedreader = new BufferedReader(inputstreamreader);
String line;
while ((line = bufferedreader.readLine()) != null)
{
System.out.println(line);
}
}
}
ps教程
来源:http://www.huiyi8.com/jiaocheng/
JAVA 监视Windows系统的进程代码
原创
©著作权归作者所有:来自51CTO博客作者严格纪律的原创作品,请联系作者获取转载授权,否则将追究法律责任
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
如何在Windows中终止占用特定端口的进程
小技巧,杀死window中占用的进程释放端口
Windows 命令提示符 搜索