LinuxContainerExecutor extends ContainerExecutor { @Override public boolean signalContainer(String user, String pid, Signal signal) throws IOException { verifyUsernamePattern(user); String runAsUser = getRunAsUser(user); String[] command = new String[] { containerExecutorExe, runAsUser, user, Integer.toString(Commands.SIGNAL_CONTAINER.getValue()), pid, Integer.toString(signal.getValue()) }; ShellCommandExecutor shExec = new ShellCommandExecutor(command); if (LOG.isDebugEnabled()) { LOG.debug("signalContainer: " + Arrays.toString(command)); } try { shExec.execute(); } catch (ExitCodeException e) { int ret_code = shExec.getExitCode(); if (ret_code == ResultCode.INVALID_CONTAINER_PID.getValue()) { return false; } LOG.warn("Error in signalling container " + pid + " with " + signal + "; exit = " + ret_code, e); logOutput(shExec.getOutput()); throw new IOException("Problem signalling container " + pid + " with " + signal + "; output: " + shExec.getOutput() + " and exitCode: " + ret_code, e); } return true; }  @Override void setConf(Configuration conf); @Override void init(); @Override void startLocalizer(Path nmPrivateContainerTokensPath,
      InetSocketAddress nmAddr, String user, String appId, String locId,
      LocalDirsHandlerService dirsHandler); @VisibleForTesting void buildMainArgs(List<String> command, String user, String appId,
      String locId, InetSocketAddress nmAddr, List<String> localDirs); @Override int launchContainer(Container container,
      Path nmPrivateCotainerScriptPath, Path nmPrivateTokensPath,
      String user, String appId, Path containerWorkDir,
      List<String> localDirs, List<String> logDirs); @Override int reacquireContainer(String user, ContainerId containerId); @Override boolean signalContainer(String user, String pid, Signal signal); @Override void deleteAsUser(String user, Path dir, Path... baseDirs); @Override boolean isContainerProcessAlive(String user, String pid); void mountCgroups(List<String> cgroupKVs, String hierarchy);  }
@Test public void testContainerKill() throws Exception { if (!shouldRun()) { return; } final ContainerId sleepId = getNextContainerId(); Thread t = new Thread() { public void run() { try { runAndBlock(sleepId, "sleep", "100"); } catch (IOException e) { LOG.warn("Caught exception while running sleep",e); } }; }; t.setDaemon(true); t.start(); assertTrue(t.isAlive()); String pid = null; int count = 10; while ((pid = exec.getProcessId(sleepId)) == null && count > 0) { LOG.info("Sleeping for 200 ms before checking for pid "); Thread.sleep(200); count--; } assertNotNull(pid); LOG.info("Going to killing the process."); exec.signalContainer(appSubmitter, pid, Signal.TERM); LOG.info("sleeping for 100ms to let the sleep be killed"); Thread.sleep(100); assertFalse(t.isAlive()); }