Linux中是否有API可以获取可用的CPU数量? 我的意思是,不使用/proc/cpuinfo或任何其他sys-node文件.
我已经找到了这个使用Schedul.h的实现:
int GetCPUCount()
{
cpu_set_t cs;
CPU_ZERO(&cs);
sched_getaffinity(0, sizeof(cs), &cs);
int count = 0;
for (int i = 0; i < 8; i++)
{
if (CPU_ISSET(i, &cs))
count++;
}
return count;
}
但是,难道没有更高层次的公共库吗?