简体   繁体   English

有没有办法获取电池信息(状态,插入等)而无需在Linux上读取proc / sys文件?

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

I want to get information about the battery in C on linux. 我想在Linux上获得有关C电池的信息。 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? acpi /内核或任何其他模块是否有任何低级接口来获取我想要的信息?

I already searched the web, but every question results in the answer "parse /proc/foo/bar". 我已经在网上搜索了,但每个问题都会得到答案“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. 最好的祝福。

The /proc filesystem does not exist on a disk. / proc文件系统不存在于磁盘上。 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. 因此,您的问题无效 - /proc文件将在内核意识到更改时发生变化。

Check this for more info about /proc file system. 检查有关的详细信息/proc文件系统。

In any case, I don't believe there's any alternative interface. 无论如何,我不相信有任何替代界面。

You might be looking for UPower: http://upower.freedesktop.org/ 您可能正在寻找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. 例如,最古老的一个是acpid ,现在已经过时了。

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. 虽然出于代码清晰的原因,我建议使用像UPower这样的轻量级抽象,但/proc和(在某种程度上) /sys被认为是Linux内核ABI的一部分,这意味着更改它们通常是不受欢迎的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM