List of utility methods to do Kill Process
void | killProcess(int port) kill Process int pid = getPid(port); if (pid == 0) { return; String[] command = { "taskkill", "/F", "/T", "/PID", Integer.toString(pid) }; if (System.getProperty("os.name").startsWith("Linux")) { String[] cmd = { "kill", "-9", Integer.toString(pid) }; command = cmd; ... |
void | killProcess(String name) kill Process try { ProcessBuilder processBuilder = new ProcessBuilder("taskkill ", "/IM", name); Process process = processBuilder.start(); BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream())); String line = null; try { while ((line = br.readLine()) != null) { } catch (Exception e) { e.printStackTrace(); if (br != null) { br.close(); } catch (Exception e) { |
void | killProcess(String processName) kill Process String command = ("killall " + processName); try { Process p = Runtime.getRuntime().exec(command.split(" ")); p.waitFor(); } catch (IOException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); ... |
boolean | killProcess(String processName) Kills the Windows process name if (isProcessRunning(processName)) { ProcessBuilder processBuilder = new ProcessBuilder(); processBuilder.command("taskkill", "/F", "/IM", processName); Process process = processBuilder.start(); process.waitFor(); return !isProcessRunning(processName); return false; ... |
void | killProcessesTree(String rootNamePart) kill Processes Tree List<String> chrome; try { chrome = getPIDsByNamePart(rootNamePart); for (String s : chrome) { int pid = Integer.parseInt(s); killChildProcesses(pid); killProcessesByNamePart(rootNamePart); ... |
boolean | killProcessNix(String pid) kill Process Nix Runtime.getRuntime().exec("kill " + pid).waitFor(); return true; |
void | killProcessWithArgs(List kill Process With Args List<String> list = new ArrayList<>(); list.add("/usr/bin/pkill"); list.addAll(args); try { Process child = new ProcessBuilder(list.toArray(new String[list.size()])).start(); child.waitFor(); } catch (InterruptedException | IOException e) { throw new RuntimeException("Can't kill process: " + e.getMessage()); ... |