window环境下调用runtime对象,直接执行tasklist的DOS命令,获取系统各进程的状态。

//列出当前系统所有进程
 public static void main(String[] args) {
 BufferedReader br = null;
 try {
 Process proc = Runtime.getRuntime().exec("tasklist");
 br = new BufferedReader(
 new InputStreamReader(proc.getInputStream()));

 System.out.println("Process info:");
 String line;
 while ((line = br.readLine()) != null) {
 System.out.println(br.readLine());
 }
 } catch (IOException e) {
 e.printStackTrace();
 } finally {
 if (br != null) {
 try {
 br.close();
 } catch (Exception e) {
 e.printStackTrace();
 }
 }
 }
 }