Finally got tired of all those time when PMS wasn't killed properly and left some old "javaw" process laying around. The first thing that came into my mind was to do the classic UNIX trick of saving the pid and the when you start a new PMS it slays that process. Windows is not that keen on supplying a equivalent to the $$ so it had to be a more advanced SharkHunter hack. The principal is the same stash the pid in a file kill the process when you start again. It is done completely from within the PMS java for the reason that I wanted this to work even if you have some custom start script.
I'll make a proper patch later this is just the code....(of course you need to call killOld() as well)
- Code: Select all
private static void killOld() throws IOException {
try {
killProc();
} catch (IOException e) {
}
dumpPid();
}
private static void killProc() throws IOException {
ProcessBuilder pb=null;
BufferedReader in = new BufferedReader(new FileReader("pms.pid"));
String pid=in.readLine();
in.close();
if(Platform.isWindows()) {
pb=new ProcessBuilder("taskkill","/F","/PID",pid,"/T");
}
else if(Platform.isFreeBSD()||Platform.isLinux()||Platform.isOpenBSD()||Platform.isSolaris())
pb=new ProcessBuilder("kill","-9",pid);
if(pb==null)
return;
try {
Process p=pb.start();
p.waitFor();
} catch (Exception e) {
debug("error kill pid "+e);
}
}
public static long getPID() {
String processName =
java.lang.management.ManagementFactory.getRuntimeMXBean().getName();
return Long.parseLong(processName.split("@")[0]);
}
private static void dumpPid() throws IOException {
FileOutputStream out=new FileOutputStream("pms.pid");
String data=String.valueOf(getPID())+"\r\n";
out.write(data.getBytes());
out.flush();
out.close();
}
