Search notes:

/sys/devices/system/cpu

Files and directories found in /sys/devices/system/cpu include:
cpu0/, cpu1/, … cpuN/ A directory for each CPU
cpufreq/
cpuidle/
hotplug/
intel_pstate/
isolated
kernel_max
microcode/
modalias
nohz_full
offline
online
possible
power
present
smt/
uevent
vulnerabilities/

Counting the number of CPUs

Because each cpu has a directory whose name is cpu followed by at least one digit, the following C program counts the numbers of CPUs in a system:
#include <stdio.h>
#include <dirent.h>
#include <sys/stat.h>
#include <string.h>
#include <ctype.h>

#define MAX_PF_NAME   1024
#define SYSFS_DEVCPU "/sys/devices/system/cpu"

int nof_cpus() {

  DIR   *dir;
  struct dirent *drd;
  struct stat    cpu_dir_stat;
  char           cpu_dir_name[MAX_PF_NAME];
  int            cpu_count = 0;


  if ((dir = opendir(SYSFS_DEVCPU)) == NULL)
     return 0;

  while ((drd = readdir(dir)) != NULL) {

     if (!strncmp(drd->d_name, "cpu", 3) && isdigit(drd->d_name[3])) {

        snprintf(cpu_dir_name, sizeof(cpu_dir_name), "%s/%s", SYSFS_DEVCPU, drd->d_name);
        cpu_dir_name[sizeof(cpu_dir_name) - 1] = '\0';

        if (stat(cpu_dir_name, &cpu_dir_stat) < 0)
           continue;

        if (S_ISDIR(cpu_dir_stat.st_mode)) {
            cpu_count++;
        }
     }
  }

  closedir(dir);

  return cpu_count;
}

int main() {
   printf("nof_cpus = %d\n", nof_cpus());
}
This code is a slightly modified version of the function get_proc_cpu_nr found in count.c of the sysstat/sysstat github repository.

See also

/proc/cpuinfo

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/Linux/fh...', 1758195173, '216.73.216.150', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/Linux/fhs/sys/devices/system/cpu/index(111): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78