Search in sources :

Example 16 with ShellCommandExecutor

use of org.apache.hadoop.util.Shell.ShellCommandExecutor in project hadoop by apache.

the class ProcessTree method isSetsidSupported.

private static boolean isSetsidSupported() {
    ShellCommandExecutor shexec = null;
    boolean setsidSupported = true;
    try {
        String[] args = { "setsid", "bash", "-c", "echo $$" };
        shexec = new ShellCommandExecutor(args);
        shexec.execute();
    } catch (IOException ioe) {
        LOG.warn("setsid is not available on this machine. So not using it.");
        setsidSupported = false;
    } finally {
        // handle the exit code
        LOG.info("setsid exited with exit code " + shexec.getExitCode());
    }
    return setsidSupported;
}
Also used : ShellCommandExecutor(org.apache.hadoop.util.Shell.ShellCommandExecutor) IOException(java.io.IOException)

Example 17 with ShellCommandExecutor

use of org.apache.hadoop.util.Shell.ShellCommandExecutor in project hadoop by apache.

the class ProcessTree method isProcessGroupAlive.

/**
   * Is the process group with  still alive?
   * 
   * This method assumes that isAlive is called on a pid that was alive not
   * too long ago, and hence assumes no chance of pid-wrapping-around.
   * 
   * @param pgrpId process group id
   * @return true if any of process in group is alive.
   */
public static boolean isProcessGroupAlive(String pgrpId) {
    ShellCommandExecutor shexec = null;
    try {
        String[] args = { "kill", "-0", "-" + pgrpId };
        shexec = new ShellCommandExecutor(args);
        shexec.execute();
    } catch (ExitCodeException ee) {
        return false;
    } catch (IOException ioe) {
        LOG.warn("Error executing shell command " + shexec.toString() + ioe);
        return false;
    }
    return (shexec.getExitCode() == 0 ? true : false);
}
Also used : ShellCommandExecutor(org.apache.hadoop.util.Shell.ShellCommandExecutor) IOException(java.io.IOException) ExitCodeException(org.apache.hadoop.util.Shell.ExitCodeException)

Example 18 with ShellCommandExecutor

use of org.apache.hadoop.util.Shell.ShellCommandExecutor in project hadoop by apache.

the class UtilTest method hasPerlSupport.

/**
   * Is perl supported on this machine ?
   * @return true if perl is available and is working as expected
   */
public static boolean hasPerlSupport() {
    boolean hasPerl = false;
    ShellCommandExecutor shexec = new ShellCommandExecutor(new String[] { "perl", "-e", "print 42" });
    try {
        shexec.execute();
        if (shexec.getOutput().equals("42")) {
            hasPerl = true;
        } else {
            LOG.warn("Perl is installed, but isn't behaving as expected.");
        }
    } catch (Exception e) {
        LOG.warn("Could not run perl: " + e);
    }
    return hasPerl;
}
Also used : ShellCommandExecutor(org.apache.hadoop.util.Shell.ShellCommandExecutor) IOException(java.io.IOException)

Example 19 with ShellCommandExecutor

use of org.apache.hadoop.util.Shell.ShellCommandExecutor in project hadoop by apache.

the class WindowsBasedProcessTree method getAllProcessInfoFromShell.

// helper method to override while testing
String getAllProcessInfoFromShell() {
    try {
        ShellCommandExecutor shellExecutor = new ShellCommandExecutor(new String[] { Shell.getWinUtilsFile().getCanonicalPath(), "task", "processList", taskProcessId });
        shellExecutor.execute();
        return shellExecutor.getOutput();
    } catch (IOException e) {
        LOG.error(StringUtils.stringifyException(e));
    }
    return null;
}
Also used : ShellCommandExecutor(org.apache.hadoop.util.Shell.ShellCommandExecutor) IOException(java.io.IOException)

Example 20 with ShellCommandExecutor

use of org.apache.hadoop.util.Shell.ShellCommandExecutor in project hadoop by apache.

the class TestProcfsBasedProcessTree method sendSignal.

private static void sendSignal(String pid, int signal) throws IOException {
    ShellCommandExecutor shexec = null;
    String[] arg = { "kill", "-" + signal, "--", pid };
    shexec = new ShellCommandExecutor(arg);
    shexec.execute();
}
Also used : ShellCommandExecutor(org.apache.hadoop.util.Shell.ShellCommandExecutor)

Aggregations

ShellCommandExecutor (org.apache.hadoop.util.Shell.ShellCommandExecutor)21 IOException (java.io.IOException)19 ExitCodeException (org.apache.hadoop.util.Shell.ExitCodeException)6 Test (org.junit.Test)3 File (java.io.File)2 ZipFile (java.util.zip.ZipFile)2 BufferedReader (java.io.BufferedReader)1 FileNotFoundException (java.io.FileNotFoundException)1 StringReader (java.io.StringReader)1 ArrayList (java.util.ArrayList)1 Configuration (org.apache.hadoop.conf.Configuration)1 FileSystem (org.apache.hadoop.fs.FileSystem)1 Path (org.apache.hadoop.fs.Path)1 DistributedFileSystem (org.apache.hadoop.hdfs.DistributedFileSystem)1 MiniDFSCluster (org.apache.hadoop.hdfs.MiniDFSCluster)1 TestContext (org.apache.hadoop.test.MultithreadedTestUtil.TestContext)1 Shell (org.apache.hadoop.util.Shell)1 YarnException (org.apache.hadoop.yarn.exceptions.YarnException)1 YarnRuntimeException (org.apache.hadoop.yarn.exceptions.YarnRuntimeException)1 Matchers.anyBoolean (org.mockito.Matchers.anyBoolean)1