Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best way to process the content of sysfs using C/C++?

Tags:

c++

c

linux

unix

The Linux kernel exposes information about the current environment using the sysfs filesystem in /sys. I'm interested in getting information about online CPUs and their memory hierarchy (Level 1 to Level 3 caches).

Since all this information is basically text files I could write a parser on my own, but I'm curious what the best way of processing the information in sysfs is. Currently I found two alternatives:

libsysfs

and

libudev

The downside of libsysfs seems to be that the code is now almost 5 years old and almost no documentation is available, libudev seems more active but documentation is quite rare. There was only one useful tutorial I found on libudev -- http://www.signal11.us/oss/udev/

What is the state of the art way to process content from sysfs in C/C++?

[Update]

Currently it is not possible to access data stored in /sys/devices/system due to the fact that the exposed information are not real devices. The only way to access this data is to do it manually.

like image 618
grundprinzip Avatar asked Jan 12 '11 20:01

grundprinzip


1 Answers

The kernel authors have published sysfs-rules.txt, which explains how sysfs must be used. They point out in particular

Do not use libsysfs

like image 81
Martin v. Löwis Avatar answered Nov 15 '22 21:11

Martin v. Löwis