List of usage examples for java.lang Process destroy
public abstract void destroy();
From source file:org.gcaldaemon.core.file.CalendarReloader.java
private final void executeScript() throws Exception { // Execute script log.debug("Executing reloader script (" + cmd + ")..."); ProcessBuilder builder = new ProcessBuilder(args); Process script = builder.start(); sleep(1000L);/*from ww w . j a va 2 s .c om*/ // Wait for script for (int i = 0; i < 15; i++) { try { script.exitValue(); } catch (Exception processNotExited) { sleep(1000L); } } // Destroy script script.destroy(); script = null; log.debug("Reloader script finished successfully."); }
From source file:org.wso2.appserver.integration.common.utils.PasswordEncryptionUtil.java
/** * By using run.sh running the ciphertool.sh and give the password as input * * @param carbonHome - carbon server installation location * @param cmdArray - commands to be executed. * @return - boolean shell script ran successfully or not * @throws IOException - Error when reading the InputStream when running shell script *//* www .j av a 2s. co m*/ public static boolean runCipherToolScriptAndCheckStatus(String carbonHome, String[] cmdArray) throws PasswordEncryptionIntegrationTestException { boolean foundTheMessage = false; BufferedReader br = null; Process process = null; try { log.info("Running the ciphertool.sh .."); File commandDir = new File(carbonHome + "/bin"); ProcessBuilder processBuilder = new ProcessBuilder(cmdArray); processBuilder.directory(commandDir); process = processBuilder.start(); br = new BufferedReader(new InputStreamReader(process.getInputStream(), "UTF-8")); String line; while ((line = br.readLine()) != null) { log.info(line); if (line.contains("Encryption is done Successfully")) { foundTheMessage = true; } } return foundTheMessage; } catch (IOException ex) { log.error("Error when reading the InputStream when running shell script ", ex); throw new PasswordEncryptionIntegrationTestException( "Error when reading the InputStream when running shell script ", ex); } finally { if (br != null) { try { br.close(); } catch (IOException e) { log.warn("error while closing the buffered reader"); } } if (process != null) { process.destroy(); } } }
From source file:com.google.wireless.speed.speedometer.measurements.PingTask.java
private void cleanUp(Process proc) { try {//ww w.ja va 2s .c om if (proc != null) { proc.destroy(); } } catch (Exception e) { Log.w(SpeedometerApp.TAG, "Unable to kill ping process", e); } }
From source file:org.kududb.client.MiniKuduCluster.java
/** * Kills the TS listening on the provided port. Doesn't do anything if the TS was already killed. * @param port port on which the tablet server is listening on * @throws InterruptedException/*from w w w. j av a 2 s.co m*/ */ public void killTabletServerOnPort(int port) throws InterruptedException { Process ts = tserverProcesses.remove(port); if (ts == null) { // The TS is already dead, good. return; } LOG.info("Killing server at port " + port); ts.destroy(); ts.waitFor(); }
From source file:org.rhq.cassandra.CassandraClusterManager.java
public void shutdown(List<Integer> nodeIds) { if (log.isDebugEnabled()) { log.debug("Preparing to shutdown cluster nodes " + collectionToString(nodeIds)); } else {//from w w w. j a v a 2 s. c o m log.info("Preparing to shutdown cluster nodes."); } File basedir = new File(deploymentOptions.getClusterDir()); for (Integer nodeId : nodeIds) { File nodeDir = new File(basedir, "node" + nodeId); log.debug("Shutting down node at " + nodeDir); try { if (!nodeDir.exists()) { log.warn("No shutdown to perform. " + nodeDir + " does not exist."); continue; } try { killNode(nodeDir); } catch (Throwable t) { log.warn("Unable to kill nodeDir [" + nodeDir + "]", t); } // This nodeProcess stuff is unlikely to be useful. I added it for Windows // support but we don't actually use this code anymore for Windows, we // use an external storage node. I'll leave it on the very off chance that // it kills some hanging around process. On Linux it will not kill // the cassandra process (see killNode above) because this is the launching // process, not the cassandra process itself. Process nodeProcess = nodeProcessMap.get(nodeId); if (null != nodeProcess) { try { nodeProcess.destroy(); } catch (Throwable t) { log.warn("Failed to kill Cassandra node " + nodeDir, t); } } } catch (Exception e) { log.warn("An error occurred trying to shutdown node at " + nodeDir); } } }
From source file:com.asakusafw.runtime.util.hadoop.ConfigurationProvider.java
private static File detectHadoopConfigurationDirectory(File command, File temporary, Map<String, String> envp) throws IOException { assert command != null; assert temporary != null; assert envp != null; prepareClasspath(temporary, ConfigurationDetecter.class); File resultOutput = new File(temporary, PATH_SUBPROC_OUTPUT); List<String> arguments = new ArrayList<>(); arguments.add(command.getAbsolutePath()); arguments.add(ConfigurationDetecter.class.getName()); arguments.add(resultOutput.getAbsolutePath()); ProcessBuilder processBuilder = new ProcessBuilder(arguments); processBuilder.environment().clear(); processBuilder.environment().putAll(envp); processBuilder.environment().put(ENV_HADOOP_CLASSPATH, temporary.getPath()); Process process = processBuilder.start(); try {//from ww w .j a v a 2 s. co m Thread redirectOut = redirect(process.getInputStream(), System.out); Thread redirectErr = redirect(process.getErrorStream(), System.err); try { int exit = process.waitFor(); redirectOut.join(); redirectErr.join(); if (exit != 0) { throw new IOException( MessageFormat.format("Failed to execute Hadoop command (exitcode={1}): {0}", arguments, String.valueOf(exit))); } } catch (InterruptedException e) { throw (IOException) new InterruptedIOException( MessageFormat.format("Failed to execute Hadoop command (interrupted): {0}", arguments)) .initCause(e); } } finally { process.destroy(); } if (resultOutput.isFile() == false) { throw new IOException( MessageFormat.format("Failed to restore Hadoop configuration path: {0}", resultOutput)); } File path = ConfigurationDetecter.read(resultOutput); return path; }
From source file:org.kududb.client.MiniKuduCluster.java
/** * Kills the master listening on the provided port. Doesn't do anything if the master was * already killed./*from ww w .ja v a 2s .c o m*/ * @param port port on which the master is listening on * @throws InterruptedException */ public void killMasterOnPort(int port) throws InterruptedException { Process master = masterProcesses.remove(port); if (master == null) { // The master is already dead, good. return; } LOG.info("Killing master at port " + port); master.destroy(); master.waitFor(); }
From source file:Main.java
public static String getSuVersion() { Process process = null; String inLine = null;//from w ww .j av a2s .c o m try { process = Runtime.getRuntime().exec("sh"); DataOutputStream os = new DataOutputStream(process.getOutputStream()); BufferedReader is = new BufferedReader( new InputStreamReader(new DataInputStream(process.getInputStream())), 64); os.writeBytes("su -v\n"); // We have to hold up the thread to make sure that we're ready to read // the stream, using increments of 5ms makes it return as quick as // possible, and limiting to 1000ms makes sure that it doesn't hang for // too long if there's a problem. for (int i = 0; i < 400; i++) { if (is.ready()) { break; } try { Thread.sleep(5); } catch (InterruptedException e) { Log.w(TAG, "Sleep timer got interrupted..."); } } if (is.ready()) { inLine = is.readLine(); if (inLine != null) { return inLine; } } else { os.writeBytes("exit\n"); } } catch (IOException e) { Log.e(TAG, "Problems reading current version.", e); return null; } finally { if (process != null) { process.destroy(); } } return null; }
From source file:org.inria.myriads.snoozenode.executor.thread.ExecutorThread.java
/** * Run method.// ww w .ja v a 2s. c o m */ @Override public void run() { log_.debug(String.format("Executing command on shell: %s", command_)); int exitCode = 1; Process process = null; try { process = Runtime.getRuntime().exec(command_); exitCode = process.waitFor(); } catch (IOException exception) { log_.error(String.format("Failed to execute the shell command: %s", exception.getMessage())); } catch (InterruptedException exception) { log_.debug(String.format("Interrupted while waiting for process to finish")); process.destroy(); return; } if (process != null) { closeStreams(process); } if (exitCode == 0) { executor_.onCommandExecuted(true); } else { executor_.onCommandExecuted(false); } }
From source file:com.mobiperf.measurements.PingTask.java
private void cleanUp(Process proc) { try {//w w w.jav a 2 s . c o m if (proc != null) { proc.destroy(); } } catch (Exception e) { Logger.w("Unable to kill ping process" + e.getMessage()); } }