Getting CPU Cores Count

master
ColumbusTech 2017-11-24 20:54:24 +03:00
parent 7948251212
commit c136939988
1 changed files with 37 additions and 0 deletions

37
Info.hpp Normal file
View File

@ -0,0 +1,37 @@
#include <cstdlib>
#include <cstdio>
#include <cstring>
namespace Columbus
{
int GetCPUCount();
int GetCPUCount()
{
#ifdef __linux__
int counter = 0;
FILE *cpuinfo = fopen("/proc/cpuinfo", "rb");
char* str;
size_t size;
while(getline(&str, &size, cpuinfo) != -1)
{
if (strstr(str, "processor") != 0)
counter++;
}
fclose(cpuinfo);
return counter;
#endif
}
}