HADOOP-13467. Shell#getSignalKillCommand should use the bash builtin on Linux. (Arpit Agarwal)

This commit is contained in:
Arpit Agarwal 2016-08-04 10:07:53 -07:00
parent f3424d662a
commit ad29c96075
2 changed files with 16 additions and 7 deletions

View File

@ -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) { if (isSetsidAvailable) {
// Use the shell-builtin as it support "--" in all Hadoop supported OSes return new String[] { "bash", "-c", "kill -" + code + " -- -" +
return new String[] {"kill", "-" + code, "--", "-" + pid}; quotedPid };
} else { } else {
return new String[] {"kill", "-" + code, pid }; return new String[] { "bash", "-c", "kill -" + code + " " +
quotedPid };
} }
} }

View File

@ -238,9 +238,11 @@ public class TestShell extends Assert {
expectedCommand = expectedCommand =
new String[]{getWinUtilsPath(), "task", "isAlive", anyPid }; new String[]{getWinUtilsPath(), "task", "isAlive", anyPid };
} else if (Shell.isSetsidAvailable) { } else if (Shell.isSetsidAvailable) {
expectedCommand = new String[] {"kill", "-0", "--", "-" + anyPid }; expectedCommand = new String[] { "bash", "-c", "kill -0 -- -'" +
anyPid + "'"};
} else { } else {
expectedCommand = new String[] {"kill", "-0", anyPid }; expectedCommand = new String[] {"bash", "-c", "kill -0 '" + anyPid +
"'" };
} }
Assert.assertArrayEquals(expectedCommand, checkProcessAliveCommand); Assert.assertArrayEquals(expectedCommand, checkProcessAliveCommand);
} }
@ -258,9 +260,11 @@ public class TestShell extends Assert {
expectedCommand = expectedCommand =
new String[]{getWinUtilsPath(), "task", "kill", anyPid }; new String[]{getWinUtilsPath(), "task", "kill", anyPid };
} else if (Shell.isSetsidAvailable) { } else if (Shell.isSetsidAvailable) {
expectedCommand = new String[] {"kill", "-9", "--", "-" + anyPid }; expectedCommand = new String[] { "bash", "-c", "kill -9 -- -'" + anyPid +
"'"};
} else { } else {
expectedCommand = new String[] {"kill", "-9", anyPid }; expectedCommand = new String[]{ "bash", "-c", "kill -9 '" + anyPid +
"'"};
} }
Assert.assertArrayEquals(expectedCommand, checkProcessAliveCommand); Assert.assertArrayEquals(expectedCommand, checkProcessAliveCommand);
} }