자바 로 컬 운영 체제 프로 세 스 목록 가 져 오기

2467 단어
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("
Error 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

좋은 웹페이지 즐겨찾기