diff options
Diffstat (limited to 'base/process_util_posix.cc')
-rw-r--r-- | base/process_util_posix.cc | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/base/process_util_posix.cc b/base/process_util_posix.cc index 3153a59..2cfa6f9 100644 --- a/base/process_util_posix.cc +++ b/base/process_util_posix.cc @@ -9,6 +9,7 @@ #include <sys/types.h> #include <sys/wait.h> #include <unistd.h> +#include <limits> #include "base/basictypes.h" #include "base/logging.h" @@ -31,6 +32,23 @@ int GetProcId(ProcessHandle process) { return process; } +int GetMaxFilesOpenInProcess() { + struct rlimit rlimit; + if (getrlimit(RLIMIT_NOFILE, &rlimit) != 0) { + return 0; + } + + // rlim_t is a uint64 - clip to maxint. + // We do this since we use the value of this function to close FD #s in a loop + // if we didn't clamp the value, doing this would be too time consuming. + rlim_t max_int = static_cast<rlim_t>(std::numeric_limits<int32>::max()); + if (rlimit.rlim_cur > max_int) { + return max_int; + } + + return rlimit.rlim_cur; +} + ProcessMetrics::ProcessMetrics(ProcessHandle process) : process_(process), last_time_(0), last_system_time_(0) { |