Hardware List with API

This is a discussion on Hardware List with API within the Linux Programming forums, part of the Platform Specific Boards category; Hi, I want to get hardware information or list in C++. As you know using system(); or exec(); is not ...

  1. #1
    Registered User
    Join Date
    Jul 2009
    Posts
    61

    Question Hardware List with API

    Hi,

    I want to get hardware information or list in C++. As you know using system(); or exec(); is not a standard way to do that and the output is distribution dependent

    In windows, we can use WMI to do that. But any API in Linux?

    Thanks

  2. #2
    Registered User
    Join Date
    Jul 2009
    Posts
    61
    There is no answer yet?

  3. #3
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by hosseinyounesi View Post
    There is no answer yet?
    If you want to really nit-pick the details, this is "kernel space" programming, ie. the API for hardware is part of the kernel API. However, the kernel is strictly C as Mr. Torvalds does not like the C++ language.

    However, the kernel already exports all the data and puts it in the /proc directory. All you have to do is parse the directory structure and text files there-in, which you can do that however you like and it will be much, much simpler and easier.
    Last edited by MK27; 07-19-2009 at 10:24 AM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  4. #4
    Registered User
    Join Date
    Jul 2009
    Posts
    61
    Ou, thanks.
    Is there any program that do the parsing of /proc and give us the details
    in a good format?!

  5. #5
    Registered User
    Join Date
    Nov 2008
    Posts
    75
    I don't know exactly what you want to do, but I don't think that you need to mess with the kernel for that. Probably you should take a look at devicekit.

    As a side note, I hope that Linux and c++ will always be 2 diverging objects, because c++ is one of the most horrible piece of cr.p I've ever seen, while c is just beatiful(I'm obviously talking about those parts where the 2 differ).

  6. #6
    Registered User
    Join Date
    Jul 2009
    Posts
    61
    I want to get hardware info like type and size of memory, name and size of hard disk, information about graphic card and so on. It's better to do that with linux API (if exists?!) in C or C++.

  7. #7
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by hosseinyounesi View Post
    I want to get hardware info like type and size of memory, name and size of hard disk, information about graphic card and so on. It's better to do that with linux API (if exists?!) in C or C++.
    /proc is mostly processes but if you look thru it you will noticed the hardware is registered there too (since they are taken care of by kernal driver modules which are processes). Eg. this is the content of /proc/asound/cards for me:
    Code:
     0 [CS4281         ]: CS4281 - Cirrus Logic CS4281
                          Cirrus Logic CS4281 at 0xfdaff000, irq 17
    You can also get much info from the "lspci" and "lsusb" commands. Read the man pages for them. I'm not sure if the /proc layout is the same and standard everywhere, but it probably is. You'll have to find out what the kernel's policy is for organizing the data.
    Last edited by MK27; 07-20-2009 at 11:55 AM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  8. #8
    Registered User
    Join Date
    Jul 2009
    Posts
    61
    Hi,
    I found something:
    and dmidecode, lshw (lshw-gtk), hwinfo. Most of them are bash files not c code or Linux API except ezix that is c code(I haven't read it's code,
    maybe using system command ) but I think in linux using bash files are common !!!!

  9. #9
    Registered User
    Join Date
    Nov 2008
    Posts
    75
    If you're searching for things like that, I guess that you could take a look at libraries like libhd(the library used by hwinfo) or libdiscover(the library used by discover). And again, even devicekit may be useful. After that, you can take a look directly at /sys and /proc.

  10. #10
    Registered User
    Join Date
    Jul 2009
    Posts
    61

    Wink

    Great, libhd is like what I want. Thansk a lot
    But about discover? It is not common and it seems that it is not used a lot

    However Thanks for your helps

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Link List math
    By t014y in forum C Programming
    Replies: 17
    Last Post: 02-20-2009, 06:55 PM
  2. instantiated from here: errors...
    By advocation in forum C++ Programming
    Replies: 5
    Last Post: 03-27-2005, 09:01 AM
  3. How can I traverse a huffman tree
    By carrja99 in forum C++ Programming
    Replies: 3
    Last Post: 04-28-2003, 06:46 PM
  4. Linked list with two class types within template.
    By SilasP in forum C++ Programming
    Replies: 3
    Last Post: 02-09-2002, 06:13 AM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 11:21 PM

Tags for this Thread


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