From ec8208f5d3480c20f7ad122c5b95bc9a6adafb20 Mon Sep 17 00:00:00 2001 From: Arun Murthy Date: Fri, 14 Aug 2009 08:16:10 +0000 Subject: [PATCH] HADOOP-6192. Fix Shell.getUlimitMemoryCommand to not rely on Map-Reduce specific configs. git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@804115 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES.txt | 3 +++ src/java/org/apache/hadoop/util/Shell.java | 31 ++++++++++++++++++++-- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 861df2f908..716b9aae5e 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -917,6 +917,9 @@ Trunk (unreleased changes) HADOOP-6188. TestTrash uses java.io.File api but not hadoop FileSystem api. (Boris Shkolnik via szetszwo) + HADOOP-6192. Fix Shell.getUlimitMemoryCommand to not rely on Map-Reduce + specific configs. (acmurthy) + Release 0.20.1 - Unreleased INCOMPATIBLE CHANGES diff --git a/src/java/org/apache/hadoop/util/Shell.java b/src/java/org/apache/hadoop/util/Shell.java index 35444c0c74..2c0ab786b8 100644 --- a/src/java/org/apache/hadoop/util/Shell.java +++ b/src/java/org/apache/hadoop/util/Shell.java @@ -63,6 +63,31 @@ abstract public class Shell { /** If or not script timed out*/ private AtomicBoolean timedOut; + /** a Unix command to get ulimit of a process. */ + public static final String ULIMIT_COMMAND = "ulimit"; + + /** + * Get the Unix command for setting the maximum virtual memory available + * to a given child process. This is only relevant when we are forking a + * process from within the Mapper or the Reducer implementations. + * Also see Hadoop Pipes and Hadoop Streaming. + * + * It also checks to ensure that we are running on a *nix platform else + * (e.g. in Cygwin/Windows) it returns null. + * @param memoryLimit virtual memory limit + * @return a String[] with the ulimit command arguments or + * null if we are running on a non *nix platform or + * if the limit is unspecified. + */ + public static String[] getUlimitMemoryCommand(int memoryLimit) { + // ulimit isn't supported on Windows + if (WINDOWS) { + return null; + } + + return new String[] {ULIMIT_COMMAND, "-v", String.valueOf(memoryLimit)}; + } + /** * Get the Unix command for setting the maximum virtual memory available * to a given child process. This is only relevant when we are forking a @@ -75,7 +100,9 @@ abstract public class Shell { * @return a String[] with the ulimit command arguments or * null if we are running on a non *nix platform or * if the limit is unspecified. + * @deprecated Use {@link #getUlimitMemoryCommand(int)} */ + @Deprecated public static String[] getUlimitMemoryCommand(Configuration conf) { // ulimit isn't supported on Windows if (WINDOWS) { @@ -90,8 +117,8 @@ abstract public class Shell { // Parse it to ensure it is legal/sane int memoryLimit = Integer.valueOf(ulimit); - - return new String[] {"ulimit", "-v", String.valueOf(memoryLimit)}; + + return getUlimitMemoryCommand(memoryLimit); } /** Set to true on Windows platforms */