问题
I want to get information about the battery in C on linux. I don't want to read or parse any file! Is there any low-level interface to acpi/the kernel or any other module to get the information I want to have?
I already searched the web, but every question results in the answer "parse /proc/foo/bar". I really don't want to do this because I think, low-level interfaces won't change as fast as Files do.
best regards.
回答1:
You might be looking for UPower: http://upower.freedesktop.org/
This is a common need for both desktop environments and mobile devices, so there have been many solutions over time. For example, one of the oldest ones was acpid
, which is pretty much obsolete now.
While I'd recommend using a light-weight abstraction like UPower for code clarity reasons, the files in /proc
and (to some extent) /sys
are considered part of the Linux kernel ABI, which means that changing them is generally frowned upon.
回答2:
The /proc filesystem does not exist on a disk. Instead, the kernel creates it in memory. They are generated on-demand by the kernel when accessed. As such, your concerns are invalid -- the /proc
files will change as quickly as the kernel becomes aware of changes.
Check this for more info about /proc
file system.
In any case, I don't believe there's any alternative interface.
来源:https://stackoverflow.com/questions/13185081/is-there-a-way-to-get-battery-info-status-plugged-in-etc-without-reading-a-p