是否有 API 可以获取 Linux 中可用的 CPU 数量?我的意思是,不使用 /proc/cpuinfo 或任何其他 sys-node 文件...
我使用 sched.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;
}
但是,使用通用库没有更高层次的东西吗?