From 8e09e19b21140193cf27de835cdad87710fd2c85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AB=8F=E8=A8=AA=E5=AD=90?= Date: Sat, 22 Jun 2024 03:56:21 +0900 Subject: =?UTF-8?q?SunOS:=20CPU=E3=81=AE=E6=83=85=E5=A0=B1=20|=20Linux:=20?= =?UTF-8?q?CPU=E6=83=85=E5=A0=B1=E3=81=AE=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/cpu.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/cpu.c b/src/cpu.c index 0e282b1..780cba1 100644 --- a/src/cpu.c +++ b/src/cpu.c @@ -1,11 +1,9 @@ #include "cpu.h" #include "common.h" -#if defined(__linux__) #include +#if defined(__linux__) #include -#elif defined(__sun) -#include #endif const char *display_cpu() { @@ -17,14 +15,11 @@ const char *display_cpu() { return run_command_s("sysctl -n hw.model | sed 's/(R)//' | " "sed 's/(TM)//' | sed 's/CPU //' | sed 's/Processor//' && " "echo \" (\" && sysctl -n hw.ncpu && echo \" core)\""); +#elif defined(__sun) + return run_command_s("psrinfo -pv | tail -1 | sed 's/(r)//g' | " + "sed 's/ CPU//' | sed 's/^ *//' && " + "echo \" (\" && psrinfo -p && echo \" core)\""); #elif defined(__linux__) - return run_command_s("cat /proc/cpuinfo | awk -F '\\\\s*: | @' " - "'/model name|Hardware|Processor|^cpu model|chip type|^cpu type/ { " - "cpu=$2; if ($1 == \"Hardware\") exit } END { print cpu }' | " - "sed 's/(R)//' | sed 's/(TM)//' | sed 's/CPU //' | sed 's/ Processor//' | " - "sed 's/ [0-9]-Core//'"); - printf(" @ "); - char buf[20]; long int val; double fmt; @@ -49,8 +44,13 @@ const char *display_cpu() { } fclose(fp); - return run_command_s("echo \"GHz (\" && nproc && echo \" core)\""); -#elif defined(__sun) - return NULL; + + return run_command_s("cat /proc/cpuinfo | awk -F '\\\\s*: | @' " + "'/model name|Hardware|Processor|^cpu model|chip type|^cpu type/ { " + "cpu=$2; if ($1 == \"Hardware\") exit } END { print cpu }' | " + "sed 's/(R)//' | sed 's/(TM)//' | sed 's/CPU //' | sed 's/ Processor//' | " + "sed 's/ [0-9]-Core//' && echo \" @ \" && " + "echo \"GHz (\" && nproc && echo \" core)\""); #endif + return NULL; } -- cgit v1.2.3