79653875

Date: 2025-06-05 06:16:13
Score: 0.5
Natty:
Report link
Runtime.availableProcessors();

public int availableProcessors() {
  return (int) Libcore.os.sysconf(_SC_NPROCESSORS_CONF);
}

You can reference the source code from https://cs.android.com.

int __get_cpu_count(const char* sys_file) {
  int cpu_count = 1;
  FILE* fp = fopen(sys_file, "re");
  if (fp != nullptr) {
    char* line = nullptr;
    size_t allocated_size = 0;
    if (getline(&line, &allocated_size, fp) != -1) {
      cpu_count = GetCpuCountFromString(line);
    }
    free(line);
    fclose(fp);
  }
  return cpu_count;
}

int get_nprocs_conf() {
  // It's unclear to me whether this is intended to be "possible" or "present",
  // but on mobile they're unlikely to differ.
  return __get_cpu_count("/sys/devices/system/cpu/possible");
}

int get_nprocs() {
  return __get_cpu_count("/sys/devices/system/cpu/online");
}
Reasons:
  • Probably link only (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: Rico