Example usage for java.lang Process destroy

List of usage examples for java.lang Process destroy

Introduction

In this page you can find the example usage for java.lang Process destroy.

Prototype

public abstract void destroy();

Source Link

Document

Kills the process.

Usage

From source file:io.cloudslang.content.utilities.util.ProcessExecutor.java

private void stopProcess(Process process, Future<ProcessResponseEntity> futureResult) {
    futureResult.cancel(true);//  w  w w .  j  a va2 s.  co m
    process.destroy();

    closeQuietly(process.getInputStream());
    closeQuietly(process.getErrorStream());
}

From source file:org.jboss.qa.jcontainer.util.executor.LoopProcessTest.java

@Test
public void loopProcess() throws IOException, InterruptedException {
    final ProcessBuilder pb = new ProcessBuilder(commands);
    final Process process = ProcessBuilderExecutor.asyncExecute(pb);
    Thread.sleep(3000);/*from   w  w  w. j a  va  2  s  .  c o m*/
    log.info("Terminate process");
    process.destroy();
    assertEquals(0, process.waitFor());
}

From source file:gov.nasa.jpf.symbc.tree.visualizer.DOTVisualizerListener.java

private void convertDotFile(File file, OUTPUT_FORMAT format) throws InterruptedException {
    String dotCmd = "dot " + file.getPath() + " -T" + format.getFormat() + " -o "
            + file.getPath().replace(".dot", "." + format.getFormat());
    try {//from  w  ww . j av a 2 s.com
        Process p = Runtime.getRuntime().exec(dotCmd);
        p.waitFor();
        p.exitValue();
        p.destroy();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:de.saly.es.example.tssl.plugin.test.multijvm.MultiJvmUnitTest.java

public void killCluster() {

    if (node != null) {
        node.close();/* www  .  ja v  a2s .  c om*/
    }

    for (final Iterator iterator = processes.iterator(); iterator.hasNext();) {
        final Process process = (Process) iterator.next();
        try {
            process.destroy();
        } catch (final Throwable e) {
            //ignore
        }
    }

}

From source file:org.jboss.qa.jcontainer.util.executor.LoopProcessTest.java

@Test
public void loopProcessRedirectIntoFile() throws IOException, InterruptedException {
    final File file = temporaryFolder.newFile();
    final ProcessBuilder pb = new ProcessBuilder(commands);
    final Process process = ProcessBuilderExecutor.asyncExecute(pb, file);
    Thread.sleep(3000);//from ww w .  j  av  a 2 s.c  o  m
    log.info("Terminate process");
    process.destroy();
    assertEquals(0, process.waitFor());
    assertThat(FileUtils.readFileToString(file), is(containsString("Sleep over")));
}

From source file:uk.ac.sanger.cgp.wwdocker.actions.Local.java

public static int execCommand(String command, Map envs, boolean shellCmd) {
    ProcessBuilder pb;//from   ww w .ja  va 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();
    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 {
                logger.info(IOUtils.toString(new FileInputStream(tempOut)));
                logger.error(IOUtils.toString(new FileInputStream(tempErr)));
                tempOut.delete();
                tempErr.delete();
            } catch (IOException e) {
                logger.error("Failed to get output from log files");
            }
        }
        if (p != null) {
            p.destroy();
            exitCode = p.exitValue();
        }
    }
    logger.trace("Exit code: " + exitCode);
    return exitCode;
}

From source file:com.linkedin.pinot.integration.tests.ChaosMonkeyIntegrationTest.java

@AfterMethod
public void tearDown() {
    for (Process process : _processes) {
        process.destroy();
    }//from   w w  w .ja  v  a 2  s  .  c o m
    FileUtils.deleteQuietly(new File(AVRO_DIR));
    FileUtils.deleteQuietly(new File(SEGMENT_DIR));
}

From source file:org.apache.hadoop.yarn.server.nodemanager.nodelabels.ScriptBasedNodeLabelsProvider.java

/**
 * Method used to terminate the Node Labels Fetch script.
 *///from   ww w . j  a  v  a2 s  . com
@Override
public void cleanUp() {
    if (shexec != null) {
        Process p = shexec.getProcess();
        if (p != null) {
            p.destroy();
        }
    }
}

From source file:uk.ac.soton.itinnovation.sad.service.services.EccIntegrationService.java

public void stop() {
    logger.debug("Shutting down ECC client threads");
    try {//from w w  w. j  a  v  a  2  s .c o  m
        int returnValue;
        for (Process p : createdProcesses) {
            p.destroy();
            logger.debug("Process shutdown signal sent, waiting for it to finish");
            returnValue = p.waitFor();
            logger.debug("Process return value: " + returnValue);
        }
    } catch (InterruptedException e) {
        logger.error("Failed to stop ECC client thread", e);
    }
}

From source file:org.sipfoundry.conference.ConfRecordThread.java

public ConfRecordThread(RecordingConfiguration recordingConfig) {
    // Check that the freeswitch initial recording directory exists
    File sourceDir = new File(sourceName);
    if (!sourceDir.exists()) {
        sourceDir.mkdirs();//from   w  ww  . ja va  2 s.  c  o m
    }

    // Create the distribution directory if it doesn't already exist.
    File destDir = new File(destName);
    if (!destDir.exists()) {
        try {
            Process process = Runtime.getRuntime().exec(new String[] { "ln", "-s", sourceName, destName });
            process.waitFor();
            process.destroy();
        } catch (IOException e) {
            LOG.error("ConfRecordThread::IOException error ", e);
        } catch (InterruptedException e) {
            LOG.error("ConfRecordThread::InterruptedException error ", e);
        }
    }

    setConfConfiguration(recordingConfig);
}