From 46b66868408fc808002bcd3fe45540e706da6711 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Fri, 20 Aug 2010 17:23:56 +0200 Subject: [PATCH] The first line no longer displays the CPU type, but only the number of CPUs --- ywho.c | 78 ++++++++++++++-------------------------------------------- 1 file changed, 19 insertions(+), 59 deletions(-) diff --git a/ywho.c b/ywho.c index 078b9a9..f0c63a3 100644 --- a/ywho.c +++ b/ywho.c @@ -203,12 +203,12 @@ memory(unsigned int i) } static void -dispsys(void) +line1(void) { FILE *f; char line[256]; - char *z, *w; - w = NULL; + char *z; + int num_cpus = 0; if (f = fopen("/proc/version", "r")) { @@ -234,61 +234,12 @@ dispsys(void) if (f = fopen("/proc/cpuinfo", "r")) { - char a[32], b[32], c[32]; - strcpy(a, "???"); - b[0] = 0; - c[0] = 0; - for(;;) + while (fgets(line, 256, f)) { - fgets(line, 256, f); - if (feof(f)) - break; - if (!strncmp(line, "cpu\t\t: ", 7)) - { - z = line+7; - w = a; - } - else if (!strncmp(line, "cpu family\t: ",13)) - { - z = line+13; strcpy(z + 1, "86\n"); - w = a; - } - else if (!strncmp(line, "model\t\t: ", 9)) - { - z = line+9; - w = b; - } - else if (!strncmp(line, "model name\t: ", 13)) - { - z = line+13; - if (!strncmp(z, "AMD-K6", 6)) - { - z[3] = ' '; - if ((w = strstr(z, "tm w/ multimedia"))) - strcpy(w, "-1\n"); - else if ((w = strstr(z, "(tm) 3D"))) - strcpy(w, "-2\n"); - } - w = b; - } - else if (!strncmp(line, "mask\t\t: ", 8)) - { - z = line+8; - w = c; - } - else - z = NULL; - if (z) - { - line[strlen(line)-1] = 0; - strcpy(w, z); - if (!strcmp(w, "Unknown")) - w[0] = 0; - } + if (!strncmp(line, "processor\t", 9)) + num_cpus++; } - printf(" on %s", *b ? b : a); - if (*c) - printf("/%s", c); + printf(" [%d CPU%s]", num_cpus, (num_cpus != 1 ? "s" : "")); fclose(f); } @@ -299,8 +250,8 @@ dispsys(void) sscanf(line, "%d.%d%d.%d", &p, &p1, &q, &q1); printf(" up "); puttime(p); - printf(" run "); - puttime(p-q); + printf(" idle "); + puttime(q); fclose(f); } @@ -313,6 +264,14 @@ dispsys(void) tm->tm_year%100, tm->tm_hour, tm->tm_min, tm->tm_sec); printf(" (%u UE)\n", (unsigned int) now); } +} + +static void +line2(void) +{ + FILE *f; + char line[256]; + char *z; if (f = fopen("/proc/loadavg", "r")) { @@ -624,7 +583,8 @@ show(void) int main(void) { readutmp(); - dispsys(); + line1(); + line2(); readproc(); solve(); sort(); -- 2.39.2