Need cpu count in linux
I would like my c++ program to get the cpu count of an intel processor with the linux operating system. I have found code on the internet but they all uses window include files and won't run under linux. I read that one can get the cpu count by typing grep -c processor /proc/cpuinfo in a linux shell but I need it in my program. Would I have to make a system call, save it to a file and then read it in?
|
Hi -
"/proc/cpuinfo" is exactly what I was going to suggest. Exactly right! You can easily read this info from C/C++ using: a) "fopen/fgets" (of the /proc/cpuinfo files), or using b) "popen()/fgets" (of the "grep /proc/cpuinfo" command). 'Hope that helps .. PSM |
But I like this even better:
# ls /sys/devices/system/cpu cpu0 cpu1 cpu2 cpu3 # |
All times are GMT -5. The time now is 03:24 PM. |