Skip to content

Commit

Permalink
0003510: Service wrapper hanging on start on Windows 2003 server
Browse files Browse the repository at this point in the history
  • Loading branch information
erilong committed Apr 9, 2018
1 parent 3d40b99 commit 154c7d3
Showing 1 changed file with 32 additions and 33 deletions.
Expand Up @@ -186,44 +186,43 @@ protected boolean isPidRunning(int pid) {
boolean isRunning = false;
if (pid != 0) {
boolean foundProcess = false;
if (!System.getProperty("os.name").contains("2003")) {
String[] path = config.getJavaCommand().split("/|\\\\");
String javaExe = path[path.length - 1].toLowerCase();
try {
ProcessBuilder pb = new ProcessBuilder("wmic", "process", String.valueOf(pid), "get", "name");
Process proc = pb.start();
BufferedReader stdout = new BufferedReader(new InputStreamReader(proc.getInputStream()));
String line = null, curLine = null;
curLine = stdout.readLine();
if (curLine != null && !curLine.trim().equals("")) {
while ((curLine = stdout.readLine()) != null) {
if (line == null && !curLine.trim().equals("")) {
line = curLine;
break;
}
String[] path = config.getJavaCommand().split("/|\\\\");
String javaExe = path[path.length - 1].toLowerCase();
try {
ProcessBuilder pb = new ProcessBuilder("wmic", "process", String.valueOf(pid), "get", "name");
Process proc = pb.start();
proc.getOutputStream().close();
BufferedReader stdout = new BufferedReader(new InputStreamReader(proc.getInputStream()));
String line = null, curLine = null;
curLine = stdout.readLine();
if (curLine != null && !curLine.trim().equals("")) {
while ((curLine = stdout.readLine()) != null) {
if (line == null && !curLine.trim().equals("")) {
line = curLine;
break;
}
}
while (stdout.read() != -1) {
}
stdout.close();
InputStream errout = proc.getErrorStream();
while (errout.read() != -1) {
}
errout.close();

if (line != null) {
String[] array = line.split("\\s+");
if (array.length > 0) {
foundProcess = true;
isRunning = array[0].toLowerCase().contains(javaExe);
if (!isRunning) {
System.out.println("Ignoring old process ID being used by " + array[0]);
}
}
while (stdout.read() != -1) {
}
stdout.close();
InputStream errout = proc.getErrorStream();
while (errout.read() != -1) {
}
errout.close();

if (line != null) {
String[] array = line.split("\\s+");
if (array.length > 0) {
foundProcess = true;
isRunning = array[0].toLowerCase().contains(javaExe);
if (!isRunning) {
System.out.println("Ignoring old process ID being used by " + array[0]);
}
}

} catch (IOException e) {
}

} catch (IOException e) {
}
if (!foundProcess) {
Kernel32Ex kernel = Kernel32Ex.INSTANCE;
Expand Down

0 comments on commit 154c7d3

Please sign in to comment.