Linux C ++:API与/proc文件? [英] Linux c++: apis vs /proc files?

查看:106
本文介绍了Linux C ++:API与/proc文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个应用程序,以收集和发送各种系统信息(分区空间/空闲空间,笔记本电脑电池信息等).我无法以直接c ++ api ..的形式获取此信息,尽管可以通过/proc(或类似文件)中的文件获得这些信息.

Im working on an app to collect and send various bits of system info (partition space/free, laptop battery info, etc). Im not having much success getting this information in the form of direct c++ api.. though its all available via files in /proc (or similar).

所以-我想知道在我的c ++应用程序中读取/解析这些文件是否是获取此信息的适当方法,还是我应该继续尝试发现API? (注意:我正在使用statvfs).

So - I'm wondering whether reading/parsing these files in my c++ app is the appropriate way to get this info or should I keep trying to discover APIs? ( NOTE: I am working with statvfs ).

到目前为止,在Win32中收集此类信息似乎更容易.看起来很奇怪.

So far it looks like it's easier to gather this sort of info in Win32. Seems strange.

推荐答案

到目前为止,最佳实践 坚持使用以下优先顺序的API.

It is best practice by far to stick with an API in the following order of precedence.

  • 您的语言API(这里对您没有太大帮助,但是对于字符串来说,使用C99字符串函数比使用Posix或其他OS标准指定的库字符串工具更好.)

  • Your language API (not much help for you here, but say for strings, a C99 string function is better to use than a library string facility specified by a Posix or other OS standard.)

Posix操作软件API

Posix operating software APIs

记录的内核API的

未公开说明的内核API(如果更改,至少它们会破坏ioctl用户,因此它们可能不会更改)

Undocumented kernel APIs (at least these will break, say, ioctl users if they change, so they probably won't change)

/proc

/dev/kmem/dev/mem

没有理由相信/proc拖钓在各个发行版之间都是可移植的,甚至是相同的.并非每个系统都安装了/proc

There is no reason to believe that /proc trolling will be portable or even the same from release to release. Not every system will even have a /proc mounted!

说了这么多, 只是从/proc刮掉东西要容易得多,如果这是唯一可用的接口,那么您应该继续使用它.qa

Having said all that, it is much easier to just scrape stuff off of /proc and if it's the only available interface then you should go ahead and use it.qa

最后,最后两个的顺序尚不完全清楚,因为/proc不适用于事后内核崩溃转储分析,但是可以窥探核心转储的工具仍然可以使用.

Finally, the ordering of the last two isn't completely clear, because /proc isn't available for a post-mortem kernel crash dump analysis, but tools that can peek in the core dump will still work.

这篇关于Linux C ++:API与/proc文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆