//进程获取
public void mpid() throws IOException {
String name = ManagementFactory.getRuntimeMXBean().getName();
// System.out.println(name);
String[] names = name.split("@");
int pid1 = Integer.parseInt(names[0]);
// 创建系统进程
ProcessBuilder pb = new ProcessBuilder("tasklist");
Process p = pb.start();
BufferedReader out = new BufferedReader(new InputStreamReader(new BufferedInputStream(p.getInputStream()), Charset.forName("GB2312")));
// System.out.println("Window 系统进程列表");
String ostr;
List<String> pid=new ArrayList<>();
while ((ostr = out.readLine()) != null) pid.add(ostr);
String [] exess={"Java.exe"};
List<String> exes=new ArrayList<>(Arrays.asList(exess));
String idp="";
idp= pid1 +",";
for (String ex : exes) {
for (String s : pid) {
String m=s.replace(" ","");
if (m.contains(ex)) {
//System.out.println(s);
idp+=m.replace(ex,"").substring(0,m.replace(ex,"").lastIndexOf("Console"))+",";
//id.add(m.replace(ex,"").substring(0,m.replace(ex,"").lastIndexOf("Console")));
}
}
}
idp=idp.substring(0, idp.length()-1);
renderJson(Co.ok("data", Ret.ok("PID", idp)));
}
java获取所有进程
最新推荐文章于 2024-08-20 04:43:18 发布