Atitit.进程管理常用api
1 常用api
进程列表 getProcessList
是否存在某个进程判断 isExistProcess
启动进程run
Sleep
Exit
Shutdown
作者:: 老哇的爪子 Attilax 艾龙, EMAIL:1466519819@qq.com
转载请注明来源: http://blog.csdn.net/attilax
2 code
Proj。atibrow
package com.attilax.lang.process;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class ProcessX {
//列出当前系统所有进程
public static void main(String[] args) {
List<String> set= getProcessList();
Collections.sort(set);
for (String string : set) {
System.out.println(string);
}
System.out.println( isExistProcess("PotPlayerMini64.exe"));
}
public static boolean isExistProcess(String string) {
List<String> li= getProcessList();
// Set<String> set=new HashSet<String>();
// set.addAll(li);
for (String line : li) {
if(line.contains(string))
return true;
}
return false;
}
public static List<String> getProcessList() {
Set<String> set=new HashSet<String>();
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());
set.add(line);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (br != null) {
try {
br.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
List<String> li=new ArrayList<String>();
li.addAll(set);
return li;
}
}
3 参考
autohotkey.chm