Howto get hardware information in Linux using C++

前端 未结 5 1872
广开言路
广开言路 2021-02-14 17:01

I need to get specifications of hard disk on both Win and *nix machines. I used on Linux like this:

   static struct hd_driveid hd;
         


        
5条回答
  •  面向向阳花
    2021-02-14 18:05

    No, there is no platform-independent way. There is even no *nix way. There is just Linux way.

    In Linux, all relevant information is available in various files in the /proc filesystem. The /proc/devices will tell you what devices there are (the files in /dev/ may exist even when the devices are not available, though opening them will fail in that case), /proc/partitions will tell you what partitions are available on each disk and than you'll have to look in the various subdirectories for the information. Just look around on some linux system where is what you need.

提交回复
热议问题