小编cha*_*hsu的帖子

从 Linux 中的 /proc 文件系统获取硬件信息

我使用execv运行lshw命令来获取 C 代码中的 CPU、磁盘和内存。但我想搜索另一种解决方案来从/proc或任何其他现有数据中获取这些信息。有什么建议吗?这是我的代码:

char *params[9]  = {"/usr/bin/lshw", "-short", "-c", "disk", 
                  "-c", "memory", "-c", "processor", 0}; //cmd params filled
execv(params[0], params);
Run Code Online (Sandbox Code Playgroud)

Linux命令:$ sudo lshw -short -c disk -c processor -c memory

$ sudo lshw -short -c disk -c processor -c memory
H/W path         Device     Class          Description
======================================================
/0/0                        memory         64KiB BIOS
/0/22                       memory         16GiB System Memory
/0/22/0                     memory         DIMM Synchronous [empty]
/0/22/1                     memory         DIMM Synchronous [empty]
/0/22/2                     memory         8GiB DIMM Synchronous 2133 MHz …
Run Code Online (Sandbox Code Playgroud)

c linux memory cpu disk

4
推荐指数
1
解决办法
4441
查看次数

标签 统计

c ×1

cpu ×1

disk ×1

linux ×1

memory ×1