Gentoo Archives: gentoo-dev

From: Nathan Zachary <nathanzachary@g.o>
To: gentoo-dev@l.g.o
Subject: Re: [gentoo-dev] [PATCH 2/3] multiprocessing.eclass: Introduce get_nproc() to get no of CPUs
Date: Wed, 14 Dec 2016 18:32:56
Message-Id: 3780389b-9578-e1a7-9779-7e8a7b19f72e@gentoo.org
In Reply to: Re: [gentoo-dev] [PATCH 2/3] multiprocessing.eclass: Introduce get_nproc() to get no of CPUs by Fabian Groffen
1 On 14/12/16 12:29, Fabian Groffen wrote:
2 > On 14-12-2016 13:01:16 -0500, Doug Freed wrote:
3 >> On Wed, Dec 14, 2016 at 12:48 PM, Nathan Zachary
4 >> <nathanzachary@g.o> wrote:
5 >>> On 14/12/16 10:11, Doug Freed wrote:
6 >>>>> I somehow doubt that would give me the expected number only, and I lack
7 >>>>> a BSD install handy to test it.
8 >>>> $(sysctl -n hw.ncpu)
9 >>>>
10 >>> I don't know that the sysctl command works universally:
11 >>>
12 >>> # sysctl -n hw.ncpu
13 >>> sysctl: cannot stat /proc/sys/hw/ncpu: No such file or directory
14 >>>
15 >> It's BSD-specific (Darwin may have it too, but I'm not in OS X at the
16 >> moment, so I can't check), which pretty much describes this branch in
17 >> the codepath as well. Linux users will have the nproc command from
18 >> coreutils.
19 > Yes, Darwin has it too, but the tool lives in /usr/sbin instead:
20 >
21 > https://gitweb.gentoo.org/repo/proj/prefix.git/tree/scripts/bootstrap-prefix.sh#n1987
22 >
23 > Fabian
24 >
25 >
26 Ah, yes, I missed the part about it being BSD-specific.
27
28 This one-liner certainly isn't as graceful or elegant, but it works:
29
30 # cat /proc/cpuinfo | grep 'processor' | wc -l

Attachments

File name MIME type
signature.asc application/pgp-signature

Replies