[Toybox] nproc(1)

enh enh at google.com
Thu May 2 09:18:39 PDT 2024


/facepalm

maybe move your hand-written version into portability just for musl,
and everyone with a working libc just uses sysconf()?

On Tue, Apr 30, 2024 at 8:26 PM Rob Landley <rob at landley.net> wrote:
>
> On 4/29/24 16:56, enh via Toybox wrote:
> > isn't nproc(1) just a call to sysconf(3) with either
> > _SC_NPROCESSORS_ONLN for regular behavior, or _SC_NPROCESSORS_CONF for
> > --all?
>
> From musl src/conf/sysconf.c:
>
>         case JT_NPROCESSORS_CONF & 255:
>         case JT_NPROCESSORS_ONLN & 255: ;
>                 unsigned char set[128] = {1};
>                 int i, cnt;
>                 __syscall(SYS_sched_getaffinity, 0, sizeof set, set);
>                 for (i=cnt=0; i<sizeof set; i++)
>                         for (; set[i]; set[i]&=set[i]-1, cnt++);
>                 return cnt;
>
> Musl returns the same thing for "conf" and "online".
>
> Rob


More information about the Toybox mailing list