Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

How to get system configuration using C++ sysconf()?

#include <iostream>
#include <thread>
#include <unistd.h>

using namespace std;
 
int main () 
{
    //threads count
   int threads = thread::hardware_concurrency();
   cout << "Supported threads : " << threads << endl;
   //processors count
   int prs = sysconf(_SC_NPROCESSORS_ONLN);
   cout << "Processors : " << prs << endl;
   //memory size
   double memory = sysconf(_SC_PHYS_PAGES) * sysconf(_SC_PAGESIZE);
   int i=0;
   for(i=0; memory >= 1024; i++)
   {
       memory/= 1024;
   }
   cout << "Memory size : " << memory << " ";
   switch(i)
   {
       case 1:
            cout << "KB";
            break;
       case 2:
            cout << "MB";
            break;
       case 3:
           cout << "GB";
           break;
       default:
            cout << "Byte";
            break;
   }
   cout << endl;
   return 0;
}

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.