Java实现Linux下双守护进程(4)
复制代码 代码如下: public class ShutDown { public static void main(String[] args) throws Exception { Configure configure = new Configure(); System.out.println("Shutdown Guards.."); for (int i
复制代码 代码如下:
public class ShutDown {
public static void main(String[] args) throws Exception {
Configure configure = new Configure();
System.out.println("Shutdown Guards..");
for (int i = 0; i < 3; i++) {
Process p = Runtime.getRuntime().exec("jps -l");
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
if (line.toLowerCase().contains("Guard".toLowerCase())) {
String[] strings = line.split("\\s{1,}");
int pid = Integer.parseInt(strings[0]);
Runtime.getRuntime().exec(configure.getKillcmd() + " " + pid);
}
}
p.waitFor();
reader.close();
p.destroy();
Thread.sleep(2000);
}
System.out.println("Guards is shutdown");
}
}
5、GuardB与GuardA类似
五、下载与使用
项目文件夹:guard_demo
下载地址:http://pan.baidu.com/s/1bn1Y6BX
如果有什么疑问或者建议,请联系我
精彩图集
精彩文章