Examples of ShellCommandExecutor


Examples of org.apache.hadoop.util.Shell.ShellCommandExecutor

  public static final long DEFAULT_SLEEPTIME_BEFORE_SIGKILL = 5000L;

  public static final boolean isSetsidAvailable = 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;
    }
  }
View Full Code Here

Examples of org.apache.hadoop.util.Shell.ShellCommandExecutor

   * Sends terminate signal to the process, allowing it to gracefully exit.
   *
   * @param pid pid of the process to be sent SIGTERM
   */
  public static void terminateProcess(String pid) {
    ShellCommandExecutor shexec = null;
    try {
      String[] args = { "kill", pid };
      shexec = new ShellCommandExecutor(args);
      shexec.execute();
    } catch (IOException ioe) {
      LOG.warn("Error executing shell command " + ioe);
    } finally {
      LOG.info("Killing process " + pid +
               " with SIGTERM. Exit code " + shexec.getExitCode());
    }
  }
View Full Code Here

Examples of org.apache.hadoop.util.Shell.ShellCommandExecutor

   * group, allowing the group to gracefully exit.
   *
   * @param pgrpId process group id
   */
  public static void terminateProcessGroup(String pgrpId) {
    ShellCommandExecutor shexec = null;
    try {
      String[] args = { "kill", "--", "-" + pgrpId };
      shexec = new ShellCommandExecutor(args);
      shexec.execute();
    } catch (IOException ioe) {
      LOG.warn("Error executing shell command " + ioe);
    } finally {
      LOG.info("Killing all processes in the process group " + pgrpId +
               " with SIGTERM. Exit code " + shexec.getExitCode());
    }
  }
View Full Code Here

Examples of org.apache.hadoop.util.Shell.ShellCommandExecutor

    //If process tree is not alive then return immediately.
    if(!ProcessTree.isAlive(pid)) {
      return;
    }
    String[] args = { "kill", "-9", pid };
    ShellCommandExecutor shexec = new ShellCommandExecutor(args);
    try {
      shexec.execute();
    } catch (IOException e) {
      LOG.warn("Error sending SIGKILL to process "+ pid + " ."+
          StringUtils.stringifyException(e));
    } finally {
      LOG.info("Killing process " + pid + " with SIGKILL. Exit code "
          + shexec.getExitCode());
    }
  }
View Full Code Here

Examples of org.apache.hadoop.util.Shell.ShellCommandExecutor

    if(!ProcessTree.isProcessGroupAlive(pgrpId)) {
      return;
    }

    String[] args = { "kill", "-9", "-"+pgrpId };
    ShellCommandExecutor shexec = new ShellCommandExecutor(args);
    try {
      shexec.execute();
    } catch (IOException e) {
      LOG.warn("Error sending SIGKILL to process group "+ pgrpId + " ."+
          StringUtils.stringifyException(e));
    } finally {
      LOG.info("Killing process group" + pgrpId + " with SIGKILL. Exit code "
          + shexec.getExitCode());
    }
  }
View Full Code Here

Examples of org.apache.hadoop.util.Shell.ShellCommandExecutor

   *
   * @param pid pid of the process to check.
   * @return true if process is alive.
   */
  public static boolean isAlive(String pid) {
    ShellCommandExecutor shexec = null;
    try {
      String[] args = { "kill", "-0", pid };
      shexec = new ShellCommandExecutor(args);
      shexec.execute();
    } catch (ExitCodeException ee) {
      return false;
    } catch (IOException ioe) {
      LOG.warn("Error executing shell command "
          + Arrays.toString(shexec.getExecString()) + ioe);
      return false;
    }
    return (shexec.getExitCode() == 0 ? true : false);
  }
View Full Code Here

Examples of org.apache.hadoop.util.Shell.ShellCommandExecutor

   *
   * @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 "
          + Arrays.toString(shexec.getExecString()) + ioe);
      return false;
    }
    return (shexec.getExitCode() == 0 ? true : false);
  }
View Full Code Here

Examples of org.apache.hadoop.util.Shell.ShellCommandExecutor

      untarCommand.append(" -)");
    } else {
      untarCommand.append(FileUtil.makeShellPath(inFile));
    }
    String[] shellCmd = { "bash", "-c", untarCommand.toString() };
    ShellCommandExecutor shexec = new ShellCommandExecutor(shellCmd);
    shexec.execute();
    int exitcode = shexec.getExitCode();
    if (exitcode != 0) {
      throw new IOException("Error untarring file " + inFile +
                  ". Tar process exited with exit code " + exitcode);
    }
  }
View Full Code Here

Examples of org.apache.hadoop.util.Shell.ShellCommandExecutor

      cmdBuf.append("-R ");
    }
    cmdBuf.append(perm).append(" ");
    cmdBuf.append(filename);
    String[] shellCmd = {"bash", "-c" ,cmdBuf.toString()};
    ShellCommandExecutor shExec = new ShellCommandExecutor(shellCmd);
    try {
      shExec.execute();
    }catch(IOException e) {
      if(Log.isDebugEnabled()) {
        Log.debug("Error while changing permission : " + filename
            +" Exception: " + StringUtils.stringifyException(e));
      }
    }
    return shExec.getExitCode();
  }
View Full Code Here

Examples of org.apache.hadoop.util.Shell.ShellCommandExecutor

   * Is the process with PID pid still alive?
   */
  private boolean isAlive(Integer pid) {
    // 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.
    ShellCommandExecutor shexec = null;
    try {
      String[] args = { "kill", "-0", pid.toString() };
      shexec = new ShellCommandExecutor(args);
      shexec.execute();
    } catch (ExitCodeException ee) {
      return false;
    } catch (IOException ioe) {
      LOG.warn("Error executing shell command "
          + Arrays.toString(shexec.getExecString()) + ioe);
      return false;
    }
    return (shexec.getExitCode() == 0 ? true : false);
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.