Gentoo Archives: gentoo-dev

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