public static String getLinuxPID(String command) {
BufferedReader reader = null;
try {
//显示所有进程
Process process = Runtime.getRuntime().exec("ps -ef");
reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line = null;
while ((line = reader.readLine()) != null) {
if (line.contains(command)) {
String[] strs = line.split("\\s+");
return strs[1];
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e) {
}
}
}
return null;
}