如何在 C/C 中以编程方式获取进程信息 来自 Solaris 系统?
是否有关于如何在 Solaris 上收集系统和进程信息的 C/C++ 库和文档?
虽然我可以解析命令行工具,但我宁愿使用一个使任务更容易完成的库。
谢谢
编辑: 建议使用 /proc 虚拟目录来收集信息,但是它并不比解析命令行工具好多少,从某种意义上说,我需要实现某种对我需要的每条数据进行自定义解析。
我正在寻找类似于 Windows 或 MacOS 的 c 库的东西,通过基于 c 的系统 API 提供此信息,但是我在 Google 上没有运气。
Is there a C/C++ library, and documentation about how to collect system and process information on Solaris?
Although I could parse command-line tools, I'd rather use a library that makes the task easier to do.
Thanks
Edit: It has been suggested to use the /proc virtual directory to collect information, however its not much better than parsing command-line tools, in the sense that I'll need to implement some sort of custom parsing for every piece of data I need.
I'm looking for something along the lines of c libraries for Windows or MacOS that provides this information through a c-based systems API, however I'm having no luck with Google.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可以使用 kstat API 获取此类信息。
您可以查看它在 OpenSolaris 中的使用方式 vmstat 和 iostat 来源。
有关 processus 的信息,我会查看 ps。
You can get this kind of information with kstat API.
You can see how it is used in OpenSolaris vmstat and iostat source.
For information about processus, I'd look at ps.
Solaris 有 /proc 虚拟目录,它允许您使用以下命令收集有关进程的各种信息文件系统 I/O 函数。
Solaris has the /proc virtual directory, which allows you to gather all sorts of information about processes using filesystem I/O functions.
我会按照 CrashWorks 的建议使用 /proc 虚拟目录。 我在 aux 和 linux 上都做过这个。 需要记住的一件事是,当我在 Linux 上使用 /proc 目录时,文件的格式因内核而异。
我不知道 Solaris 方面的情况如何,但这可能意味着您的解决方案无法从一个 Solaris 平台移植到另一个平台。
I would use the /proc virutal dir as CrashWorks has suggested. I've done this on both aux and linux. One thing to keep in mind is when I did use the /proc dir on linux the format of the files varied from one kernel to another.
I don't know what the situation is like on the Solaris side but this could mean that your solution will not be portable from one solaris platform to another.
getrusage()
怎么样?what about
getrusage()
?我绝对不是这个主题的专家,但上学期我在一项作业中做了一些非常类似的事情,当时我们被要求拍摄流程快照。 不幸的是,这种方法需要深入内核,这可能不是您想要做的。
我发现这篇文章很有帮助。
无论如何,这里有一些片段。
您需要锁定某些数据结构的想法,否则有时内核会挂起。 “for_each_process”是在某处定义的宏,但我不记得它是如何工作的 D:
我的一些同学采取了不同的方法并深入研究了“ps”实用程序的源代码。 我相信我正在 Linux 2.6.18-92.1.13.e15 上工作。 免责声明:这对我有用,但您的里程可能会有所不同。 我很可能会偏离正轨,但我不想把你引向错误的方向。
I'm definately not an expert on the subject, but I did something very similar for an assignment last semester when we were required to take snapshots of processes. Unfortunately this method requires digging into the kernel which is probably not what you want to do.
I found this article helpful.
Anyways here are some snippets.
The idea you need to lock down some data structures or sometimes the kernel will hang. "for_each_process" is a macro defined somewhere but I don't remember how it works D:
Some of my classmates took different approaches and dived into the source of the "ps" utility. I believe I was working on Linux 2.6.18-92.1.13.e15. Disclaimer: This worked for me but your mileage may vary. I could very well be off the wall and I don't want to lead you down the wrong direction.