Linux Version number and hardwares list

This is a discussion on Linux Version number and hardwares list within the C++ Programming forums, part of the General Programming Boards category; Hi, I am looking for a C/C++ code to get the Linux Version number and the hardwares list in the ...

  1. #1
    Registered User
    Join Date
    May 2009
    Posts
    3

    Linux Version number and hardwares list

    Hi,

    I am looking for a C/C++ code to get the Linux Version number and the hardwares list in the system like drive size, RAM size etc.

    Also, Is is possible to get the OS version and hardwares list using same code on any linux flavour?? For e.g. Fedora, ubuntu, Debian etc?

    Can anyone suggest some code for this.

    Any help is greatly appreciated.

    Thanks
    Arun

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Getting the version number will not be too difficult.

    When it comes to listing the hardware, there are probably plenty of solutions out there, but I don't think it's trivial. It obviously depends a lot on how much details you need to get out of there. Just listing the mounted drives isn't too hard (just display /etc/mnttab or some such).

    There is /proc/devices which contains some useful information - in fact, /proc contains a fair amount of what you may need to get out of there.
    Top-level Files in the proc File System

    lspci will list all PCI (and PCI-e, PCI-x, AGP and any other related buses).

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    May 2009
    Posts
    3
    Hi matsp,

    Thanks a lot for the reply! I really appreciate such quick answer. Thats what is so lovely about Linux, "Enthusiasm & Passion"

    I have posted the same question on other forums also and got similar replies(Linux rocks!! Again and always :0) ) But the answers have Linux commands in it to try.

    Well, As I wrote I want some solution which I could code, so should I assume to execute the required commands in C/C++ code using system() or execl()??

    Also, Will this solution work for all Linux flavors or on the widely used flavors altleast like RHEL, Fedora, Ubuntu, Debian, CentOS, OpenSuse etc. I want to deploy an app that will send the system details about of the end-user system, their web activities, hardwares list, installed and currently running applications. The app will send the details to a server which provides the admins the usage behaviors in the network.

    Any more pointers will really help.

    Thumbs up!
    Arun

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Some of the /proc content, you could simply use fopen() to open it, fgets() to read the data, and then use some home-built parsing code to grok out the info you need.

    You could of course look at the source of lspci and copy that into your app, but that may be more than you want to do, so calling lspci using popen() and read from the resulting pipe-handle would be a better option.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21