以nginx进程为例子
private final static String NAME_STRING = "nginx.exe"; //传入进程名称processName public static boolean findProcess() { BufferedReader bufferedReader = null; try { Process proc = Runtime.getRuntime().exec("tasklist -fi " + '"' + "imagename eq " + NAME_STRING +'"'); bufferedReader = new BufferedReader(new InputStreamReader(proc.getInputStream())); String line = null; while ((line = bufferedReader.readLine()) != null) { if (line.contains(NAME_STRING)) { return true; } } return false; } catch (Exception ex) { ex.printStackTrace(); return false; } finally { if (bufferedReader != null) { try { bufferedReader.close(); } catch (Exception ex) {} } } }