amitp
amitp

Reputation: 283

Hardware recognition in user space Linux

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

Upvotes: 4

Views: 375

Answers (3)

nick black
nick black

Reputation: 366

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.

Upvotes: 0

Michael Berg
Michael Berg

Reputation: 453

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.

Upvotes: 4

Alexander Kjäll
Alexander Kjäll

Reputation: 4336

It uses the klogctl call.

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

Upvotes: 0

Related Questions