summaryrefslogtreecommitdiffstats
path: root/src/libnetdata/os/get_pid_max.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libnetdata/os/get_pid_max.c')
-rw-r--r--src/libnetdata/os/get_pid_max.c45
1 files changed, 29 insertions, 16 deletions
diff --git a/src/libnetdata/os/get_pid_max.c b/src/libnetdata/os/get_pid_max.c
index 45027961..70372a74 100644
--- a/src/libnetdata/os/get_pid_max.c
+++ b/src/libnetdata/os/get_pid_max.c
@@ -2,13 +2,27 @@
#include "../libnetdata.h"
-pid_t pid_max = 32768;
+pid_t pid_max = 4194304;
+
pid_t os_get_system_pid_max(void) {
+ static bool read = false;
+ if(read) return pid_max;
+ read = true;
+
#if defined(OS_MACOS)
+ int mib[2];
+ int maxproc;
+ size_t len = sizeof(maxproc);
+
+ mib[0] = CTL_KERN;
+ mib[1] = KERN_MAXPROC;
+
+ if (sysctl(mib, 2, &maxproc, &len, NULL, 0) == -1) {
+ pid_max = 99999; // Fallback value
+ nd_log(NDLS_DAEMON, NDLP_ERR, "Cannot find system max pid. Assuming %d.", pid_max);
+ }
+ else pid_max = (pid_t)maxproc;
- // As we currently do not know a solution to query pid_max from the os
- // we use the number defined in bsd/sys/proc_internal.h in XNU sources
- pid_max = 99999;
return pid_max;
#elif defined(OS_FREEBSD)
@@ -17,41 +31,40 @@ pid_t os_get_system_pid_max(void) {
if (unlikely(GETSYSCTL_BY_NAME("kern.pid_max", tmp_pid_max))) {
pid_max = 99999;
- netdata_log_error("Assuming system's maximum pid is %d.", pid_max);
- } else {
- pid_max = tmp_pid_max;
+ nd_log(NDLS_DAEMON, NDLP_ERR, "Cannot get system max pid. Assuming %d.", pid_max);
}
+ else
+ pid_max = tmp_pid_max;
return pid_max;
#elif defined(OS_LINUX)
- static char read = 0;
- if(unlikely(read)) return pid_max;
- read = 1;
-
char filename[FILENAME_MAX + 1];
snprintfz(filename, FILENAME_MAX, "%s/proc/sys/kernel/pid_max", netdata_configured_host_prefix?netdata_configured_host_prefix:"");
unsigned long long max = 0;
if(read_single_number_file(filename, &max) != 0) {
- netdata_log_error("Cannot open file '%s'. Assuming system supports %d pids.", filename, pid_max);
+ nd_log(NDLS_DAEMON, NDLP_ERR, "Cannot open file '%s'. Assuming system supports %d pids.", filename, pid_max);
return pid_max;
}
if(!max) {
- netdata_log_error("Cannot parse file '%s'. Assuming system supports %d pids.", filename, pid_max);
+ nd_log(NDLS_DAEMON, NDLP_ERR, "Cannot parse file '%s'. Assuming system supports %d pids.", filename, pid_max);
return pid_max;
}
pid_max = (pid_t) max;
return pid_max;
-#else
+#elif defined(OS_WINDOWS)
- // just a big default
+ pid_max = (pid_t)0x7FFFFFFF;
+ return pid_max;
+
+#else
- pid_max = 4194304;
+ // return the default
return pid_max;
#endif