4 ms·
nproc isn't available on some of the BSDs
by skizziepop 6y ago
nproc isn't available on some of the BSDs
- oso2k 6y agoRight. So on Mac or other BSDs, you want use a ‘sysctl’.
- oso2k 6y agoAnother 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.
- sigjuice 6y agohttps://github.com/mirror/busybox/blob/master/coreutils/nproc.c https://github.com/mirror/busybox/blob/master/coreutils/npro...
- floatingatoll 6y agoOn 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.
- stewartesmith 6y agoNot just Macs, plenty of Linux systems have a big.LITTLE design. with a big.LITTLE system it'll really depend what you're doing. Just compiling something? It's probably fine (if all cores can be active at once). If you're wanting more consistent performance for some calculations? You might need to think a bit more.
- toast0 6y agocpuset -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 6y ago$ nproc ksh: nproc: not found $ uname -a OpenBSD obsd64.example.xyz 6.8 GENERIC.MP#828 arm64 $ sysctl hw.ncpu hw.ncpu=2