bmk_cores_linux.c 383 B

123456789101112131415161718192021
  1. #include <stdio.h>
  2. int bmx_get_core_count() {
  3. int cores = 0;
  4. char buffer[1024];
  5. FILE * fp = popen("cat /proc/cpuinfo |grep -c '^processor'", "r");
  6. if (fp == NULL) {
  7. printf("Failed to run command\n" );
  8. return 1;
  9. }
  10. while (fgets(buffer, sizeof(buffer), fp) != NULL) {
  11. cores = atoi(buffer);
  12. }
  13. pclose(fp);
  14. return cores;
  15. }