有没有一种方法可以获取电池信息(状态,插入状态等),而无需在Linux上读取proc/sys文件? [英] Is there a way to get battery info (status, plugged in, etc) without reading a proc/sys file on linux?
问题描述
我想获取有关Linux上C语言中电池的信息.我不想要读取或解析任何文件! acpi/内核或任何其他模块是否有任何低级接口来获取我想要的信息?
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?
我已经在网上搜索了,但是每个问题都会得到答案"parse/proc/foo/bar".我真的不想这样做,因为我认为底层接口的更改不会像File那样快.
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.
最诚挚的问候.
推荐答案
您可能正在寻找UPower: http://upower.freedesktop.org/
You might be looking for UPower: http://upower.freedesktop.org/
这是台式机环境和移动设备的普遍需求,因此随着时间的推移,出现了许多解决方案.例如,最古老的版本之一是acpid
,现在已经过时了.
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.
尽管出于代码清晰的原因,我建议使用诸如UPower之类的轻量级抽象,但/proc
和(在某种程度上)/sys
中的文件被视为Linux内核ABI的一部分,这意味着对其进行更改通常会皱眉.
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.
这篇关于有没有一种方法可以获取电池信息(状态,插入状态等),而无需在Linux上读取proc/sys文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!