标签:
package com.wa.xwolf.sblog.util; import java.io.BufferedInputStream; import java.io.BufferedReader; import java.io.InputStreamReader; import java.nio.charset.Charset; public class ProcessUtil { public static void main(String[] args) throws Exception { // 创建系统进程 ProcessBuilder pb = new ProcessBuilder("tasklist"); Process p = pb.start(); BufferedReader out = new BufferedReader(new InputStreamReader(new BufferedInputStream(p.getInputStream()), Charset.forName("GB2312"))); BufferedReader err = new BufferedReader(new InputStreamReader(new BufferedInputStream(p.getErrorStream()))); System.out.println("Window 系统进程列表"); String ostr; while ((ostr = out.readLine()) != null) System.out.println(ostr); String estr = err.readLine(); if (estr != null) { System.out.println("\nError Info"); System.out.println(estr); } } }
控制台输出:
Window 系统进程列表 映像名称 PID 会话名 会话# 内存使用 ========================= ======== ================ =========== ============ System Idle Process 0 Services 0 24 K System 4 Services 0 4,600 K smss.exe 372 Services 0 176 K csrss.exe 548 Services 0 1,680 K wininit.exe 624 Services 0 360 K csrss.exe 632 Console 1 52,584 K winlogon.exe 680 Console 1 2,024 K services.exe 724 Services 0 4,804 K lsass.exe 740 Services 0 5,632 K lsm.exe 748 Services 0 1,564 K svchost.exe 844 Services 0 3,408 K svchost.exe 952 Services 0 4,200 K svchost.exe 1068 Services 0 10,508 K svchost.exe 1100 Services 0 41,200 K svchost.exe 1128 Services 0 18,856 K svchost.exe 1252 Services 0 6,656 K 复制代码
标签:
原文地址:http://my.oschina.net/u/2001537/blog/484842