API用于检查有关CPU、内存、网络、NAT表使用情况的信息
我正在开发一个嵌入式 Linux 系统(2.6 内核和 uclibc),我需要检查 cpu、内存、网络、NAT 表使用情况等...
我应该使用哪个 API?我可以在哪里查看?我访问了一些有关 Linux 内核 API 的网站,但没有找到任何直接的信息。有什么建议或推荐吗?
我的程序是用 C 语言编写的,使用 uclibc 和 gcc 3.4.6
谢谢
I am developing an embedded Linux system (2.6 kernel and uclibc) and I need to check for cpu, memory, network, NAT Table usage, etc...
Which API should I use? Where can i check it? I have visited some websites about the Linux kernel API but didnt find any direct information about. Any suggestion or recommendation?
My program is written in C with uclibc and gcc 3.4.6
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要的所有信息(以及更多信息)都可以在 procfs 中找到:
/proc/uptime
、/proc/stat
/ proc/meminfo
/proc/net/dev
/proc/net/ip_conntrack
顺便说一句:GCC 3.4.6 非常旧了。目前维护的最旧版本是4.4;如果可能的话我建议升级。 Buildroot 将为您自动完成许多过程。
All the information you're after (and much, much more) is available in procfs:
/proc/uptime
,/proc/stat
/proc/meminfo
/proc/net/dev
/proc/net/ip_conntrack
As an aside: GCC 3.4.6 is reeealllly old. The oldest currently maintained version is 4.4; I'd recommend upgrading if possible. Buildroot will automate a lot of the process for you.
proc 文件系统相当优化:它是一个虚拟文件系统,其中所有内容实际上都是在读取时创建的。因此,如果没有人读取信息,则不会生成信息。
基于文本文件的界面的优点在于它同时是人类可读和机器可读的。其次,不存在字节序问题和类似的问题——它在跨架构上工作得更好。
与运行 ioctl(为包括 V4L 和 ALSA 在内的一些子系统完成)相比,它的优点在于它也是编译器(例如#pragma pack)和 ABI 独立 - 如果您喜欢恐怖故事,请向 ARM 开发人员询问 OABI 到 EABI 的更改...
请注意,procfs 和 sysfs 的内容被视为稳定内核接口的一部分,不允许开发人员随意更改任何内容。
the proc file system is fairly optimal: it is a virtual file system, where all of the contents are actually created upon a read. So if noone reads info, it isn't generated.
The beauty of a text file-based interface is that it is both human readable and machine readable at the same time. Secondly, there are no endianess issues and things like that - it works better across architectures.
Compared to running ioctls, which was done for a few subsystems including V4L and ALSA, it has the beauty that it is also compiler (e.g. #pragma pack) and ABI independent - ask ARM developers about the OABI to EABI change if you enjoy horror stories...
Note that the contents of procfs and sysfs are considered part of the stable kernel interfaces, no developer is allowed to change anything at random.