]> granicus.if.org Git - sysstat/commitdiff
Find the maximum number of the CPU, not the total number of CPUs in online
authorAlexander Troosh <trush@yandex.ru>
Tue, 8 Oct 2013 15:55:07 +0000 (19:55 +0400)
committerAlexander Troosh <trush@yandex.ru>
Tue, 8 Oct 2013 15:55:07 +0000 (19:55 +0400)
count.c

diff --git a/count.c b/count.c
index 0d95f8ad2034d4d957be215e569d05209b58f641..a7604a4fa0eae8c3ac88fb2adea54af6d4bdf16d 100644 (file)
--- a/count.c
+++ b/count.c
@@ -58,7 +58,7 @@ int get_sys_cpu_nr(void)
        struct dirent *drd;
        struct stat buf;
        char line[MAX_PF_NAME];
-       int proc_nr = 0;
+       int num_proc, proc_nr = -1;
 
        /* Open relevant /sys directory */
        if ((dir = opendir(SYSFS_DEVCPU)) == NULL)
@@ -66,14 +66,16 @@ int get_sys_cpu_nr(void)
 
        /* Get current file entry */
        while ((drd = readdir(dir)) != NULL) {
-
                if (!strncmp(drd->d_name, "cpu", 3) && isdigit(drd->d_name[3])) {
                        snprintf(line, MAX_PF_NAME, "%s/%s", SYSFS_DEVCPU, drd->d_name);
                        line[MAX_PF_NAME - 1] = '\0';
                        if (stat(line, &buf) < 0)
                                continue;
                        if (S_ISDIR(buf.st_mode)) {
-                               proc_nr++;
+                               sscanf(&drd->d_name[3], "%d", &num_proc);
+                               if (num_proc > proc_nr) {
+                                       proc_nr = num_proc;
+                               }
                        }
                }
        }
@@ -81,7 +83,7 @@ int get_sys_cpu_nr(void)
        /* Close directory */
        closedir(dir);
 
-       return proc_nr;
+       return (proc_nr + 1);
 }
 
 /*