java擷取本地作業系統進程列表

來源:互聯網
上載者:User

標籤:

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 KSystem                           4 Services                   0      4,600 Ksmss.exe                       372 Services                   0        176 Kcsrss.exe                      548 Services                   0      1,680 Kwininit.exe                    624 Services                   0        360 Kcsrss.exe                      632 Console                    1     52,584 Kwinlogon.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複製代碼

 


java擷取本地作業系統進程列表

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.