List of usage examples for java.lang Process destroy
public abstract void destroy();
From source file:uk.ac.sanger.cgp.wwdocker.interfaces.Workflow.java
default int cleanDockerPath(BaseConfiguration config) { String command = baseDockerCommand(config, null); List<String> args = new ArrayList(Arrays.asList(command.split(" "))); args.add("/bin/bash"); args.add("-c"); args.add("rm -rf /datastore/oozie-* /datastore/*.ini /datastore/logs.tar.gz /datastore/toInclude.lst"); ProcessBuilder pb = new ProcessBuilder(args); Map<String, String> pEnv = pb.environment(); pEnv.putAll(Config.getEnvs(config)); logger.info("Executing: " + String.join(" ", args)); int exitCode = -1; Process p = null; try {//from w w w. j a v a 2 s. c o m p = pb.start(); String progErr = IOUtils.toString(p.getErrorStream()); String progOut = IOUtils.toString(p.getInputStream()); exitCode = p.waitFor(); Utils.logOutput(progErr, Level.ERROR); Utils.logOutput(progOut, Level.TRACE); } catch (InterruptedException | IOException e) { logger.error(e.getMessage(), e); } finally { if (p != null) { p.destroy(); exitCode = p.exitValue(); } } return exitCode; }
From source file:org.apache.kudu.client.MiniKuduCluster.java
private void destroyAndWaitForProcess(Process process) throws InterruptedException { process.destroy(); process.waitFor(); }
From source file:org.apache.pig.impl.streaming.ExecutableManager.java
/** * Helper function to close input and output streams * to the process and kill it/*from w w w. ja va2 s. c om*/ * @param process the process to be killed * @throws IOException */ private void killProcess(Process process) throws IOException { if (process != null) { inputHandler.close(process); outputHandler.close(); process.destroy(); } }
From source file:eu.udig.omsbox.OmsBoxPlugin.java
public void addProcess(Process process, String id) { Process tmp = runningProcessesMap.get(id); if (tmp != null) { tmp.destroy(); }/*from w ww . ja v a 2 s. co m*/ runningProcessesMap.put(id, process); }
From source file:com.asakusafw.runtime.util.hadoop.ConfigurationProviderTest.java
/** * search for confdir auto.// w w w.j a v a2 s . co m * @throws Exception if failed */ @Test public void newInstance_auto() throws Exception { File cmd = putExec("testing/testcmd"); File site = putConf("auto/core-site.xml"); try (PrintWriter writer = new PrintWriter(cmd)) { writer.printf("#/bin/sh\n"); writer.printf("if [ $# -eq 0 ]\n"); writer.printf("then\n"); writer.printf(" exit 0\n"); writer.printf("elif [ $# -ne 2 ]\n"); writer.printf("then\n"); writer.printf(" exit 1\n"); writer.printf("else\n"); writer.printf(" if [ \"$1\" != '%s' ]\n", ConfigurationDetecter.class.getName()); writer.printf(" then\n"); writer.printf(" exit 1\n"); writer.printf(" fi\n"); writer.printf(" echo '%s' > \"$2\"\n", site.getParentFile().getAbsolutePath()); writer.printf(" exit 0\n"); writer.printf("fi\n"); } try { Process proc = new ProcessBuilder(cmd.getAbsolutePath()).start(); try { int exitCode = proc.waitFor(); Assume.assumeThat(exitCode, is(0)); } finally { proc.destroy(); } } catch (Exception e) { System.out.println("Failed to execute bash script"); e.printStackTrace(System.out); Assume.assumeNoException(e); } Map<String, String> envp = new HashMap<>(); envp.put("HADOOP_CMD", cmd.getAbsolutePath()); Configuration conf = new ConfigurationProvider(envp).newInstance(); assertThat(isLoaded(conf), is(true)); }
From source file:savant.plugin.Tool.java
@Override public void init(JPanel panel) { mainPanel = panel;/*from w ww . ja v a2s . co m*/ panel.setLayout(new CardLayout()); JPanel settingsPanel = new ToolSettingsPanel(this); panel.add(new JScrollPane(settingsPanel), "Settings"); JPanel waitCard = new JPanel(); waitCard.setLayout(new GridBagLayout()); // Left side filler. GridBagConstraints gbc = new GridBagConstraints(); gbc.gridwidth = GridBagConstraints.REMAINDER; gbc.fill = GridBagConstraints.HORIZONTAL; gbc.insets = new Insets(5, 100, 0, 100); waitCard.add(new JLabel(getDescriptor().getName()), gbc); progressBar = new JProgressBar(); progressBar.setPreferredSize(new Dimension(240, progressBar.getPreferredSize().height)); waitCard.add(progressBar, gbc); progressInfo = new JLabel(); progressInfo.setAlignmentX(1.0f); Font f = progressInfo.getFont(); f = f.deriveFont(f.getSize() - 2.0f); progressInfo.setFont(f); waitCard.add(progressInfo, gbc); cancelButton = new JButton("Cancel"); cancelButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { if (toolProc != null) { Process p = toolProc; toolProc = null; p.destroy(); } showCard("Settings"); } }); gbc.fill = GridBagConstraints.NONE; waitCard.add(cancelButton, gbc); // Console output at the bottom. console = new JTextArea(); console.setFont(f); console.setLineWrap(false); console.setEditable(false); JScrollPane consolePane = new JScrollPane(console); consolePane.setPreferredSize(new Dimension(800, 200)); gbc.weighty = 1.0; gbc.insets = new Insets(30, 5, 5, 5); gbc.fill = GridBagConstraints.BOTH; waitCard.add(consolePane, gbc); panel.add(waitCard, "Progress"); }
From source file:org.apache.accumulo.minicluster.MiniAccumuloCluster.java
/** * Stops Accumulo and Zookeeper processes. If stop is not called, there is a shutdown hook that is setup to kill the processes. However its probably best to * call stop in a finally block as soon as possible. *//*from w ww . j ava2 s. c o m*/ public void stop() throws IOException, InterruptedException { for (LogWriter lw : logWriters) { lw.flush(); } if (zooKeeperProcess != null) { zooKeeperProcess.destroy(); } if (masterProcess != null) { masterProcess.destroy(); } synchronized (tabletServerProcesses) { if (tabletServerProcesses != null) { for (Process tserver : tabletServerProcesses) { tserver.destroy(); } } } if (gcProcess != null) { gcProcess.destroy(); } zooKeeperProcess = null; masterProcess = null; gcProcess = null; tabletServerProcesses.clear(); if (config.useMiniDFS() && miniDFS != null) miniDFS.shutdown(); for (Process p : cleanup) p.destroy(); miniDFS = null; }
From source file:com.playonlinux.framework.WinePrefix.java
/** * Create the prefix and load its parameters. The prefix will be set as initialized * @param version version of wine//www. j a v a 2 s . c om * @param architecture architecture of wine * @return the same object * @throws CancelException if the prefix cannot be created or if the user cancels the operation */ public WinePrefix create(String version, String architecture) throws CancelException { if (prefix == null) { throw new ScriptFailureException("Prefix must be selected!"); } try { wineInstallation = new WineInstallation.Builder() .withPath(playOnLinuxContext.makeWinePathFromVersionAndArchitecture(version, Architecture.valueOf(architecture))) .withApplicationEnvironment(playOnLinuxContext.getSystemEnvironment()).build(); } catch (PlayOnLinuxException e) { throw new ScriptFailureException(e); } ProgressStep progressStep = this.setupWizard.progressBar( String.format(translate("Please wait while the virtual drive is being created..."), prefixName)); ObservableDirectorySize observableDirectorySize; try { observableDirectorySize = new ObservableDirectorySize(prefix.getWinePrefixDirectory(), 0, NEWPREFIXSIZE); } catch (PlayOnLinuxException e) { throw new ScriptFailureException(e); } observableDirectorySize.setCheckInterval(10); observableDirectorySize.addObserver(progressStep); backgroundServicesManager.register(observableDirectorySize); Process process; try { process = wineInstallation.createPrefix(this.prefix); } catch (IOException e) { throw new ScriptFailureException("Unable to create the wineprefix", e); } try { process.waitFor(); } catch (InterruptedException e) { process.destroy(); killall(); throw new CancelException(e); } finally { observableDirectorySize.deleteObserver(progressStep); backgroundServicesManager.unregister(observableDirectorySize); } return this; }
From source file:com.att.aro.datacollector.ioscollector.utilities.AppSigningHelper.java
public void executeCmd(String cmd) { System.out.println(cmd);//from w w w . j a v a 2 s .c o m ProcessBuilder pbldr = new ProcessBuilder(); if (!Util.isWindowsOS()) { pbldr.command(new String[] { "bash", "-c", cmd }); } else { pbldr.command(new String[] { "CMD", "/C", cmd }); } try { Process proc = pbldr.start(); try { Thread.sleep(1000 * 2); } catch (InterruptedException e) { e.printStackTrace(); } proc.destroy(); } catch (IOException e) { //Do nothing } }
From source file:de.uzk.hki.da.convert.PublishVideoConversionStrategy.java
/** * @author Daniel M. de Oliveira//from www . ja v a2s . c o m * @author Christian Weitz * @author Thomas Kleinke * * @param cmd The command to execute * @param targetFile The target file to check regularly * @return true if the conversion was successful, otherwise false */ private boolean executeConversionTool(String[] cmd, File targetFile) { logger.debug("Running cmd \"{}\"", Arrays.toString(cmd)); Process p = null; try { ProcessBuilder pb = new ProcessBuilder(cmd); p = pb.start(); long targetFileSize = 0; long previousTargetFileSize = 0; do { previousTargetFileSize = targetFileSize; Thread.sleep(processTimeout); targetFileSize = targetFile.length(); } while (previousTargetFileSize < targetFileSize); p.destroy(); } catch (FileNotFoundException e) { logger.error("File not found in runShellCommand", e); return false; } catch (Exception e) { logger.error("Error in runShellCommand", e); return false; } finally { if (p != null) LinuxEnvironmentUtils.closeStreams(p); } return true; }