Skip to content

Commit

Permalink
fix:closeBrowser方法使用 process.waitFor
Browse files Browse the repository at this point in the history
  • Loading branch information
fanyong920 committed Jan 17, 2025
1 parent 8c991d3 commit 63a191c
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/main/java/com/ruiyun/jvppeteer/cdp/core/BrowserRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,25 +110,23 @@ public void destroy() {
this.destroyProcess(this.process);
return;
}
Process exec = null;
String command = "";
this.destroyProcess(this.process);
Process exec;
String command;
if (Helper.isLinux() || Helper.isMac()) {
command = "kill -9 " + pid;
exec = Runtime.getRuntime().exec(new String[]{"/bin/sh", "-c", command});
} else {
if (this.process.isAlive()) {
command = "cmd.exe /c taskkill /PID " + pid + " /F /T ";
command = "cmd.exe /c taskkill /pid " + pid + " /F /T ";
exec = Runtime.getRuntime().exec(command);
}
}
try {
if (exec != null) {
if (Objects.nonNull(exec)) {
if(LOGGER.isDebugEnabled()){
LOGGER.debug("kill chrome process by pid,command: {}", command);
}
exec.waitFor(Constant.DEFAULT_TIMEOUT, TimeUnit.MILLISECONDS);
}
this.destroyProcess(this.process);
} finally {
this.destroyProcess(exec);
}
Expand All @@ -149,8 +147,11 @@ public void destroyProcess(Process process) {
return;
}
process.destroy();
if (process.isAlive()) {
process.destroyForcibly();
try {
process.waitFor(30L, TimeUnit.SECONDS);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
LOGGER.error("operation interrupt", e);
}
}

Expand Down

0 comments on commit 63a191c

Please sign in to comment.