Programmatically Getting The Number Of (Online) CPUs On Linux

In case you wondered, if you want to know how many online (aka working) CPUs there are inside a program, use:

const int nCPUs = sysconf(_SC_NPROCESSORS_ONLN);

Note that man sysconf doesn’t mention many of the configuration bits you may ask about. See /usr/include/bits/confname.h for more options.