tags:

views:

130

answers:

3

I want to be able to inspect my Linux machine hardware in C. How do I get the information that appear in dmesg in C ? For example, for keyboard the message is input: AT Translated Set 2 keyboard as /devices/platform/i8042/serio0/input/input0 I want to get in my program the label, AT Translated Set 2, and the path, /devices/platform/i8042/serio0/input/input0. Any idea how to do so ?

amit

A: 

It uses the klogctl call.

Best thing is to read the source code yourself, it can be downloaded here: util-linux

Alexander Kjäll
I do not want the use dmesg. I want to do find the info without query dmesg output
amitp
+4  A: 

You can also look at the contents of files in /proc.

/proc/version, /proc/ioports, /proc/iomem, /proc/meminfo, and others have a lot of information in them.

The files under /proc/bus have additional information about the system's hardware devices.

I'd also recommend looking at the source code for usbutils and pciutils for example code to get the output from the lsusb and lspci commands respectively.

Michael Berg
A: 

You would want to use libhal, and connect to the hal daemon. If HAL isn't there, look for a mounted sysfs partition. Check out /sys/devices, or work backwards through /sys/bus.

If neither HAL nor sysfs is available, reconsider your approach or restrict your scope.

nick black