List of usage examples for java.lang Process destroy
public abstract void destroy();
From source file:org.graylog.plugins.backup.strategy.AbstractMongoBackupStrategy.java
protected synchronized void processCommand(List<String> command) throws Exception { //need to find a a smart way to manage processBuilder ProcessBuilder pb = new ProcessBuilder(command); pb.redirectErrorStream(true);// www . ja v a 2 s . c o m Process p = pb.start(); Timer timeOut = new Timer(); timeOut.schedule(new TimerTask() { @Override public void run() { if (p.isAlive()) { LOG.warn("restore process take more than 15 sec I'll destroy it"); p.destroy(); } } //this parameter need to be configurable }, 15000); p.waitFor(); timeOut.cancel(); }
From source file:org.mashupmedia.encode.ProcessManager.java
public boolean killProcess(long mediaItemId, MediaContentType mediaContentType) { ProcessQueueItem processQueueItem = getProcessQueueItem(mediaItemId, mediaContentType); if (processQueueItem == null) { return false; }// ww w .java 2 s . c o m Process process = processQueueItem.getProcess(); if (process != null) { process.destroy(); } boolean isRemoved = processQueueItems.remove(processQueueItem); return isRemoved; }
From source file:com.orange.clara.cloud.servicedbdumper.dbdumper.core.CoreDumper.java
private void runDump(DatabaseDriver databaseDriver, String fileName) throws IOException, InterruptedException, RunProcessException { String[] commandLine = databaseDriver.getDumpCommandLine(); int i = 1;/*from ww w.ja v a2 s.co m*/ while (true) { Process p = this.runCommandLine(commandLine); try { this.filer.store(p.getInputStream(), fileName); } catch (IOException e) { } catch (Exception e) { if (p.isAlive()) { p.destroy(); } throw e; } p.waitFor(); if (p.exitValue() == 0) { break; } if (i >= this.dbCommandRetry) { this.filer.delete(fileName); throw new RunProcessException("\nError during process (exit code is " + p.exitValue() + "): "); } logger.warn("Retry {}/{}: fail to dump data for file {}.", i, dbCommandRetry, fileName); Thread.sleep(10000); i++; } }
From source file:org.mashupmedia.encode.ProcessManager.java
public void killProcesses(long mediaItemId) { List<ProcessQueueItem> processQueueItemsToBeDeleted = getProcessQueueItems(mediaItemId); if (processQueueItemsToBeDeleted == null || processQueueItemsToBeDeleted.isEmpty()) { return;//from ww w.j a v a2 s . c om } for (ProcessQueueItem processQueueItem : processQueueItemsToBeDeleted) { Process process = processQueueItem.getProcess(); if (process != null) { process.destroy(); } processQueueItemsToBeDeleted.remove(processQueueItem); } }
From source file:com.web.controller.ToolController.java
@ResponseBody @RequestMapping(value = "/tool/verifyapk", method = RequestMethod.POST) public String verifyApk(@RequestParam("apkfile") MultipartFile file) { //keytool -list -printcert -jarfile d:\weixin653android980.apk //keytool -printcert -file D:\testapp\META-INF\CERT.RSA //System.out.println("12345"); try {/*from ww w . j a va 2s . c om*/ OutputStream stream = new FileOutputStream(new File(file.getOriginalFilename())); BufferedOutputStream outputStream = new BufferedOutputStream(stream); outputStream.write(file.getBytes()); outputStream.flush(); outputStream.close(); Runtime runtime = Runtime.getRuntime(); String ccString = "keytool -list -printcert -jarfile C:\\Users\\Administrator\\Desktop\\zju1.1.8.2.apk"; Process p = runtime.exec(ccString); BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream())); StringBuilder sb = new StringBuilder(); while (br.readLine() != null) { sb.append(br.readLine() + "<br/>"); } p.destroy(); p = null; return sb.toString(); } catch (FileNotFoundException fe) { return fe.getMessage(); } catch (IOException ioe) { return ioe.getMessage(); } }
From source file:org.apache.hadoop.util.NodeHealthScriptRunner.java
/** * Method used to terminate the node health monitoring service. * //from www . j a v a 2 s . co m */ @Override protected void serviceStop() { if (nodeHealthScriptScheduler != null) { nodeHealthScriptScheduler.cancel(); } if (shexec != null) { Process p = shexec.getProcess(); if (p != null) { p.destroy(); } } }
From source file:uk.ac.sanger.cgp.wwdocker.actions.Local.java
public static Map<String, String> execCapture(String command, Map envs, boolean shellCmd) { Map<String, String> result = new HashMap(); ProcessBuilder pb;/*from w w w .j a v a 2 s .co m*/ if (shellCmd) { pb = new ProcessBuilder("/bin/sh", "-c", command); } else { pb = new ProcessBuilder(command.split(" ")); } Map<String, String> pEnv = pb.environment(); if (envs != null) { pEnv.putAll(envs); } logger.info("Executing: " + command); int exitCode = -1; Process p = null; File tempOut = null; File tempErr = null; try { tempOut = File.createTempFile("wwdExec", ".out"); tempErr = File.createTempFile("wwdExec", ".err"); pb.redirectOutput(tempOut); pb.redirectError(tempErr); p = pb.start(); exitCode = p.waitFor(); } catch (InterruptedException | IOException e) { logger.error(e.getMessage(), e); } finally { if (tempOut != null && tempErr != null) { try { result.put("stdout", StringUtils.chomp(IOUtils.toString(new FileInputStream(tempOut)))); result.put("stderr", StringUtils.chomp(IOUtils.toString(new FileInputStream(tempErr)))); tempOut.delete(); tempErr.delete(); logger.info(result.get("stdout")); logger.error(result.get("stderr")); } catch (IOException e) { logger.error("Failed to get output from log files"); } } if (p != null) { p.destroy(); exitCode = p.exitValue(); } } result.put("exitCode", Integer.toString(exitCode)); return result; }
From source file:com.thoughtworks.go.util.ProcessWrapper.java
private void close(Process p) { try {/*from ww w . j a v a 2 s .c o m*/ IOUtils.closeQuietly(p.getInputStream()); IOUtils.closeQuietly(p.getOutputStream()); IOUtils.closeQuietly(p.getErrorStream()); } finally { if (p != null) { p.destroy(); } } }
From source file:com.alfaariss.oa.authentication.password.digest.HtPasswdMD5Digest.java
private void testCommand() throws OAException { Runtime r = Runtime.getRuntime(); Thread t = null;/*from w ww . j a va2s . c om*/ String[] saCommand = null; try { saCommand = resolveCommand(_sCommand, "salt", "password"); _systemLogger.debug("Executing test command: " + resolveCommand(saCommand)); final Process p = r.exec(saCommand); t = new Thread(new Runnable() { public void run() { try { Thread.sleep(3000); p.destroy(); _systemLogger.warn("Destroyed process"); } catch (InterruptedException e) { _systemLogger.debug("Thread interrupted"); } } }); t.start(); int exitCode = p.waitFor(); if (exitCode != 0) { StringBuffer sbError = new StringBuffer("Configured command returned exit code '"); sbError.append(exitCode); sbError.append("': "); sbError.append(resolveCommand(saCommand)); _systemLogger.error(sbError.toString()); throw new OAException(SystemErrors.ERROR_INIT); } } catch (OAException e) { throw e; } catch (Exception e) { _systemLogger.error("Could not execute command: " + resolveCommand(saCommand), e); throw new OAException(SystemErrors.ERROR_INIT); } finally { if (t != null) t.interrupt(); } }
From source file:org.ourgrid.common.executor.vbox.VirtualBoxEnvironment.java
private void stopVm() throws ExecutorException { getLogger().debug("About to kill secure environment"); buildAndRunProcess(createStopVmCommand(), "Unable to kill virtual environment"); Process execProcess = getExecProcess(); if (execProcess != null) { execProcess.destroy(); }//from w ww . j av a2 s. c o m }