On Macs, this "total cores available" strategy might not be a valid approach, since you probably only want to be using the high-performance cores and not also the low-power ones — and the CPU might well overbook all your threads to high-perf to leave room for the OS and other programs, even if you try to do otherwise.
Another thought, I don’t know if Alpine Linux or other musl-libc based systems will have ‘nproc’ if, for instance, you’re running containers or other minimal systems.
cpuset -g on FreeBSD >= 7.1 will tell you what cpus are available to your shell, where a sysctl will only tell you what's on your system. (Lots of good info in the related manual pages)
sigjuice|5 years ago
oso2k|5 years ago
floatingatoll|5 years ago
oso2k|5 years ago
toast0|5 years ago