Is there a way to get battery info (status, plugged in, etc) without reading a proc/sys file on linux?

核能气质少年 提交于 2020-01-03 15:21:28

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!