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;
}
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);
}
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;
}
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;
}
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();
}
Aggregations