]> arthur.barton.de Git - netdata.git/blobdiff - src/common.c
Merge pull request #1575 from simonnagl/feature/macOS
[netdata.git] / src / common.c
index 28ba72594d47cef1535d0611e2755dbad8ad4d68..f6f2ee1a40c761e0a95a4fdcf0a614d7767ee3a7 100644 (file)
@@ -1101,6 +1101,18 @@ int processors = 1;
 long get_system_cpus(void) {
     processors = 1;
 
+    #ifdef __APPLE__
+        int32_t tmp_processors;
+
+        if (unlikely(GETSYSCTL("hw.logicalcpu", tmp_processors))) {
+            error("Assuming system has %d processors.", processors);
+        } else {
+            processors = tmp_processors;
+        }
+
+        return processors;
+    #else
+
     char filename[FILENAME_MAX + 1];
     snprintfz(filename, FILENAME_MAX, "%s/proc/stat", global_host_prefix);
 
@@ -1130,10 +1142,19 @@ long get_system_cpus(void) {
 
     debug(D_SYSTEM, "System has %d processors.", processors);
     return processors;
+
+    #endif /* __APPLE__ */
 }
 
 pid_t pid_max = 32768;
 pid_t get_system_pid_max(void) {
+    #ifdef __APPLE__
+        // 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;
+    #else
+
     char filename[FILENAME_MAX + 1];
     snprintfz(filename, FILENAME_MAX, "%s/proc/sys/kernel/pid_max", global_host_prefix);
     procfile *ff = procfile_open(filename, NULL, PROCFILE_FLAG_DEFAULT);
@@ -1159,6 +1180,8 @@ pid_t get_system_pid_max(void) {
     procfile_close(ff);
     debug(D_SYSTEM, "System supports %d pids.", pid_max);
     return pid_max;
+
+    #endif /* __APPLE__ */
 }
 
 unsigned int hz;