Get hardware information from /proc filesytem in Linux

后端 未结 3 1620
既然无缘
既然无缘 2021-01-14 07:35

I use execv to run lshw command to get the CPU, disk, and memory in C code. But I would like to search another solution to get these information fr

3条回答
  •  长情又很酷
    2021-01-14 08:31

    By reading the source code of lshw, I found that lshw read raw data from /sys/class/dmi/. Because lshw is written in CPP that I am not familiar with, there is a question Where does dmidecode get the SMBIOS table? mentioned that dmidecode.c read raw data from /sys/class/dmi that's same as lshw does.

    Here are the definitions in dmidecode.c

    #define SYS_ENTRY_FILE "/sys/firmware/dmi/tables/smbios_entry_point"
    #define SYS_TABLE_FILE "/sys/firmware/dmi/tables/DMI"
    

    I extract code from dmidecode.c to get the CPU and memory information, and use lsscsi to get disk information.

    Thanks for your help.

提交回复
热议问题