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 (St Ring[] args) throws Exception {//Create system process 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 System process list"); 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); } }}
Console output:
Window system Process list image name PID session name Session # Memory use ========================= ======== =========== ===== =========== ============system Idle Process 0 Services 0 Ksystem 4 Services 0 4,600 Ksmss.exe 372 services 0 176 Kcsrss.exe 548 Services 0 1,680 Kwininit.exe 6 Services 0 Kcsrss.exe 632 Console 1 52,584 Kwi Nlogon.exe 680 Console 1 2,024 Kservices.exe 724 Services 0 4,804 Klsass.exe 740 Services 0 5,632 Klsm.exe 748 Services 0 1,564 Ksvchost.exe 844 Services 0 3,408 Ksvchost.exe 952 Services 0 4,200 Ksvchost.exe 1068 Services 0 10,508 Ksvchost.exe 1100 Services 0 41,200 Ksvchost.exe 1128 Services 0 18,856 Ksvchost.exe 1252 Services 0 6,656 K Copy Code
Java get list of local operating system processes