diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/Shell.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/Shell.java index 6c74601117a..f98fbf983c5 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/Shell.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/Shell.java @@ -311,11 +311,16 @@ public abstract class Shell { } } + // Use the bash-builtin instead of the Unix kill command (usually + // /bin/kill) as the bash-builtin supports "--" in all Hadoop supported + // OSes. + final String quotedPid = bashQuote(pid); if (isSetsidAvailable) { - // Use the shell-builtin as it support "--" in all Hadoop supported OSes - return new String[] {"kill", "-" + code, "--", "-" + pid}; + return new String[] { "bash", "-c", "kill -" + code + " -- -" + + quotedPid }; } else { - return new String[] {"kill", "-" + code, pid }; + return new String[] { "bash", "-c", "kill -" + code + " " + + quotedPid }; } } diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestShell.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestShell.java index be7b3328eb4..c5b4bc260ac 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestShell.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestShell.java @@ -238,9 +238,11 @@ public class TestShell extends Assert { expectedCommand = new String[]{getWinUtilsPath(), "task", "isAlive", anyPid }; } else if (Shell.isSetsidAvailable) { - expectedCommand = new String[] {"kill", "-0", "--", "-" + anyPid }; + expectedCommand = new String[] { "bash", "-c", "kill -0 -- -'" + + anyPid + "'"}; } else { - expectedCommand = new String[] {"kill", "-0", anyPid }; + expectedCommand = new String[] {"bash", "-c", "kill -0 '" + anyPid + + "'" }; } Assert.assertArrayEquals(expectedCommand, checkProcessAliveCommand); } @@ -258,9 +260,11 @@ public class TestShell extends Assert { expectedCommand = new String[]{getWinUtilsPath(), "task", "kill", anyPid }; } else if (Shell.isSetsidAvailable) { - expectedCommand = new String[] {"kill", "-9", "--", "-" + anyPid }; + expectedCommand = new String[] { "bash", "-c", "kill -9 -- -'" + anyPid + + "'"}; } else { - expectedCommand = new String[] {"kill", "-9", anyPid }; + expectedCommand = new String[]{ "bash", "-c", "kill -9 '" + anyPid + + "'"}; } Assert.assertArrayEquals(expectedCommand, checkProcessAliveCommand); }