java如何獲取本地操作系統(tǒng)進程列表
更新時間:2015年07月29日 16:55:48 作者:alonelywolf
本文介紹了java中是如何獲取當(dāng)前本地操作系統(tǒng)正在運行的系統(tǒng)進程的信息,需要的朋友可以參考下
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 { // 創(chuàng)建系統(tǒng)進程 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 系統(tǒng)進程列表"); 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); } } }
控制臺輸出:
以上就是本文的全部內(nèi)容,希望大家可以熟練掌握java獲取本地操作系統(tǒng)進程列表的方法。
相關(guān)文章
SpringBoot+Redis實現(xiàn)數(shù)據(jù)字典的方法
這篇文章主要介紹了SpringBoot+Redis實現(xiàn)數(shù)據(jù)字典的方法,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-10-10解決使用RestTemplate時報錯RestClientException的問題
這篇文章主要介紹了解決使用RestTemplate時報錯RestClientException的問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2021-08-08IDEA使用Maven創(chuàng)建module出現(xiàn)Ignored?pom.xml問題及解決
這篇文章主要介紹了IDEA使用Maven創(chuàng)建module出現(xiàn)Ignored?pom.xml問題及解決方案,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2023-11-11