JAVA查找windows进程

公司的一个播控软件老是卡死,所以做了个监控软件来实现自动启动,其中用了Process来查找系统进程。

具体方法如下:

 1     // 创建系统进程
 2     @SuppressWarnings("AlibabaCommentsMustBeJavadocFormat")
 3     public static boolean read() {
 4         Process proc = null;
 5         try {
 6             proc = Runtime.getRuntime().exec("tasklist /FI \"IMAGENAME eq " + "EBCS.exe" + "\"");
 7             BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new BufferedInputStream(proc.getInputStream()), Charset.forName("GB2312")));
 8             String line = null;
 9             while ((line = bufferedReader.readLine()) != null) {
10                 if (line.contains("EBCS.exe")) {
11                     return true;
12                 }
13             }
14         } catch (IOException e) {
15             e.printStackTrace();
16         }
17         return false;
18     }

 

posted @ 2020-03-11 21:24  守护时光  阅读(1337)  评论(0编辑  收藏  举报