Skip to content
Advertisement

Get hardware information from /proc filesytem in Linux

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 from /proc or any other existed data. Have any suggestion? Here is my code:

JavaScript

Linux command: $ sudo lshw -short -c disk -c processor -c memory

JavaScript

I have two questions:

  • Where to find a guide to parse the files in /proc to get these hardware information?
  • Do I need to trace the source code of lshw to find what does lshw do?

Edit:

Chapter 7 of Advanced Linux Programming is a guide to parse the /proc filesystem.

Advertisement

Answer

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

JavaScript

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

Thanks for your help.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement