How to get the number of CPUs in Linux using C?

后端 未结 8 1674
情歌与酒
情歌与酒 2020-11-29 20:17

Is there an API to get the number of CPUs available in Linux? I mean, without using /proc/cpuinfo or any other sys-node file...

I\'ve found this implementation using

8条回答
  •  一生所求
    2020-11-29 21:01

    #include 
    #include 
    
    int main(int argc, char *argv[])
    {
        printf("This system has %d processors configured and "
            "%d processors available.\n",
            get_nprocs_conf(), get_nprocs());
        return 0;
    }
    

    https://linux.die.net/man/3/get_nprocs

提交回复
热议问题