【发布时间】:2021-04-26 07:42:13
【问题描述】:
这是扫描以下有关 /proc/cpuinfo 的信息的代码(它有效)。使用%*s 我可以跳过为每一行存储特定列。因此,跳过 5 次后,我可以存储 vendor_id。但是为什么之后要跳过4次才能拿到cpu族呢?
{
int fd = open("/proc/cpuinfo", O_RDONLY);
char *buffer = (char *)malloc(BUFF_SIZE);
int length = read(fd, buffer, BUFF_SIZE);
sscanf(buffer, "%*s %*s %*s %*s %*s %s %*s %*s %*s %s %*s %*s %s",
vendor_id, cpu_family, cpu_model);
}
【问题讨论】:
-
你不是跳过 4 次,而是跳过 3 次。一种用于
cpu,一种用于family,一种用于:。 -
您可能会发现 libcpuid 很有趣,它可以作为解析
/proc/cpuinfo的替代方法(也适用于其他操作系统)。