diff options
author | 諏訪子 <suwako@076.moe> | 2024-06-18 13:39:02 +0900 |
---|---|---|
committer | 諏訪子 <suwako@076.moe> | 2024-06-18 13:39:02 +0900 |
commit | 7effecbcd3fd8869d32448d6ae6b5f1ccb0efe08 (patch) | |
tree | 009536efa7d2342eacb72517f9af24a86b4f0ecd /src/cpu.c | |
parent | e09858229410af502ff0b0b3ce000d0495641353 (diff) |
起動時間とCPU
Diffstat (limited to 'src/cpu.c')
-rw-r--r-- | src/cpu.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/cpu.c b/src/cpu.c new file mode 100644 index 0000000..9b79eca --- /dev/null +++ b/src/cpu.c @@ -0,0 +1,35 @@ +#include "memory.h" + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> + +void run_cpu_command(const char *command) { + char buf[128]; + + FILE *p = popen(command, "r"); + if (!p) { + fprintf(stderr, "ホストコマンドを実効に失敗: %s", command); + return; + } + + while (fgets(buf, sizeof(buf), p) != NULL) { + buf[strcspn(buf, "\n")] = '\0'; + printf("%s", buf); + } + + pclose(p); +} + +void display_cpu() { +#if defined(__NetBSD__) + run_cpu_command("sysctl -n machdep.cpu_brand | sed 's/(R)//' | " + "sed 's/(TM)//' | sed 's/CPU //'"); + run_cpu_command("echo \" (\" && sysctl -n hw.ncpu && echo \" core)\""); +#elif defined(__FreeBSD__) || defined(__OpenBSD__) + run_cpu_command("sysctl -n hw.model | sed 's/(R)//' | " + "sed 's/(TM)//' | sed 's/CPU //'"); + run_cpu_command("echo \" (\" && sysctl -n hw.ncpu && echo \" core)\""); +#elif defined(__linux__) +#endif +} |