I am writing a small C application that use some threads for processing data. I want to be able to know the number of processors on a certain machine, without using system() & in combination to a small script.
The only way i can think of is to parse /proc/cpuinfo. Any other useful suggestions ?
As others have mentioned in comments, this answer is useful:
Leaving as a solution for folks that might skip over comments...
The following was the code that I used to figure number of cores.....it might help you
(t>>16)&0xff contains the number cores........
I guess this could help you http://lists.gnu.org/archive/html/autoconf/2002-08/msg00126.html
Why not use sys/sysinfo.h?
Way more information can be found on the man page
If you have a machine with sysfs, take a look in /sys/devices/system/cpu.
Make sure you're asking for what you want -- CPUs, cores, hyperthreads, etc.