title: How to get the number of CPUs in Linux using C?
body: <p>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...</p>
  <p>I've found this implementation using sched.h:</p>
  <pre><code>int GetCPUCount()
  {
   cpu_set_t cs;
   CPU_ZERO(&amp;cs);
   sched_getaffinity(0, sizeof(cs), &amp;cs);
  
   int count = 0;
   for (int i = 0; i &lt; 64; i++)
   {
    if (CPU_ISSET(i, &amp;cs))
     count++;
    else
     break;
   }
   return count;
  }
  </code></pre>
  <p>But, isn't there anything more higher level using common libraries?</p>