Re: git: 48bfd3597654 - main - Add nproc(1)
- Reply: Mateusz Guzik : "Re: git: 48bfd3597654 - main - Add nproc(1)"
- In reply to: Mateusz Guzik : "git: 48bfd3597654 - main - Add nproc(1)"
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Wed, 08 Feb 2023 20:27:36 UTC
Mateusz Guzik wrote in <202302081947.318Jlbt6052826@gitrepo.freebsd.org>: ... |URL: https://cgit.FreeBSD.org/src/commit/?id=48bfd3597654490cdc43bf0f591\ |a539d3a28b590 ... | Add nproc(1) Hey! Great. (NPROC is mentioned in POSIX for environment variables, as well as a make macro that did not make it, .. and nproc(1) is commonly used on Linux it seems.) Thanks. | This program prints the number of CPU threads it can run on, while | respecting cpusets (or not, depending on switches). | | It aims to be compatible with nproc as found in GNU coreutils. That, "however", ... |+ if (all_flag) { |+ cpus = sysconf(_SC_NPROCESSORS_ONLN); is not compatible -- note i like the FreeBSD way better, and maybe someone should make a bug report even. #?0|kent:$ getconf -a|grep NPROC _NPROCESSORS_CONF 8 _NPROCESSORS_ONLN 4 #?0|kent:$ nproc 4 #?0|kent:$ nproc --all 8 #?0|kent:$ |+ if (cpus == -1) |+ err(1, "sysconf"); |+ } else { |+ CPU_ZERO(&mask); |+ if (cpuset_getaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TID, -1, |+ sizeof(mask), &mask) != 0) |+ err(1, "cpuset_getaffinity"); |+ cpus = CPU_COUNT(&mask); That is the right thing to do, imho! Thank you. --steffen | |Der Kragenbaer, The moon bear, |der holt sich munter he cheerfully and one by one |einen nach dem anderen runter wa.ks himself off |(By Robert Gernhardt)