Example usage for org.apache.hadoop.mapreduce.util ProcessTree isSetsidAvailable

List of usage examples for org.apache.hadoop.mapreduce.util ProcessTree isSetsidAvailable

Introduction

In this page you can find the example usage for org.apache.hadoop.mapreduce.util ProcessTree isSetsidAvailable.

Prototype

boolean isSetsidAvailable

To view the source code for org.apache.hadoop.mapreduce.util ProcessTree isSetsidAvailable.

Click Source Link

Usage

From source file:it.crs4.pydoop.mapreduce.pipes.TaskLog.java

License:Apache License

/**
 * Construct the command line for running the task JVM
 * @param setup The setup commands for the execed process.
 * @param cmd The command and the arguments that should be run
 * @param stdoutFilename The filename that stdout should be saved to
 * @param stderrFilename The filename that stderr should be saved to
 * @param tailLength The length of the tail to be saved.
 * @return the command line as a String//ww w . j  av  a2s .  c  om
 * @throws IOException
 */
static String buildCommandLine(List<String> setup, List<String> cmd, File stdoutFilename, File stderrFilename,
        long tailLength, boolean useSetsid) throws IOException {

    String stdout = FileUtil.makeShellPath(stdoutFilename);
    String stderr = FileUtil.makeShellPath(stderrFilename);
    StringBuffer mergedCmd = new StringBuffer();

    // Export the pid of taskJvm to env variable JVM_PID.
    // Currently pid is not used on Windows
    if (!Shell.WINDOWS) {
        mergedCmd.append(" export JVM_PID=`echo $$` ; ");
    }

    if (setup != null && setup.size() > 0) {
        mergedCmd.append(addCommand(setup, false));
        mergedCmd.append(";");
    }
    if (tailLength > 0) {
        mergedCmd.append("(");
    } else if (ProcessTree.isSetsidAvailable && useSetsid && !Shell.WINDOWS) {
        mergedCmd.append("exec setsid ");
    } else {
        mergedCmd.append("exec ");
    }
    mergedCmd.append(addCommand(cmd, true));
    mergedCmd.append(" < /dev/null ");
    if (tailLength > 0) {
        mergedCmd.append(" | ");
        mergedCmd.append(tailCommand);
        mergedCmd.append(" -c ");
        mergedCmd.append(tailLength);
        mergedCmd.append(" >> ");
        mergedCmd.append(stdout);
        mergedCmd.append(" ; exit $PIPESTATUS ) 2>&1 | ");
        mergedCmd.append(tailCommand);
        mergedCmd.append(" -c ");
        mergedCmd.append(tailLength);
        mergedCmd.append(" >> ");
        mergedCmd.append(stderr);
        mergedCmd.append(" ; exit $PIPESTATUS");
    } else {
        mergedCmd.append(" 1>> ");
        mergedCmd.append(stdout);
        mergedCmd.append(" 2>> ");
        mergedCmd.append(stderr);
    }
    return mergedCmd.toString();
}