java获取本地操作系统进程列表

2018-07-20    来源:open-open

容器云强势上线!快速搭建集群,上万Linux镜像随意使用
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

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点!
本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。

上一篇:DES算法java实现

下一篇:java中常用的时间处理类TimeUtil