//进程获取
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)));
}
标签:String,系统,idp,replace,获取,ex,进程,new,out From: https://www.cnblogs.com/zcxxcvbn/p/16879959.html