how to find number of cpu (cores) available for application?

Alexander Tormasov a.tormasov at
Fri Jul 24 10:56:05 CEST 2020

I am trying to understand how many cpu or/and cored are available for running application.

I check code related to sysctl in libports/src/lib/libc/<>
and found
extern "C" int __sysctl(const int *name, u_int namelen,
void *oldp, size_t *oldlenp,
const void *newp, size_t newlen)
/* fallback values */
switch(index_a) {

case CTL_HW: switch(index_b) {

*oldlenp = 0;
return 0;

case HW_NCPU:
*(int*)oldp = 1;
*oldlenp = sizeof(int);
return 0;

} break;

in short, if I used standardised for BSD code (like below in golang) it always return 1!

int mib[2], out;
size_t len;

mib[0] = CTL_HW;
mib[1] = HW_NCPU;
len = sizeof(out);
if(sysctl(mib, 2, &out, &len, NULL, 0) >= 0)
return (int32)out;
return 0;

Any suggestions? How I can have portable code for Genode to obtain at least NCPU?


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the users mailing list