使用 getrusage
作为 这个问题的延续,我想知道是否可以获得一些简单的示例代码关于如何利用 getrusage。我想用它来查找进程使用的CPU时间,最好是从PID。
我正在使用 Cocoa、Objective_C,当然还有 C。任何帮助都会很棒!
谢谢
As a continuation of this question I'm wondering if I can get some simple sample code as to how to make use of getrusage. I would like to use it to find the time CPU used by a process, ideally from the PID.
I'm working in Cocoa, Objective_C and of course C. Any help would be awesome!
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我对 OS X 不太确定,但就其价值而言,如果这是在 Linux 上,那么从
/proc/
下的文件读取将是一个相当简单的问题。不过,OS X 似乎没有procfs
(至少不是标准的),所以这个答案将属于“任何帮助”类别。 :)I'm not so sure about OS X, but for what it's worth, if this were on Linux it would be a fairly simple matter of reading from a file underneath
/proc/<pid>
. OS X doesn't seem to haveprocfs
(at least, not standard), though, so this answer will fall into the "any help" category. :)因此,我找到了如何使用 此处 和 < a href="https://stackoverflow.com/questions/1469495/unix-programming-struct-timeval-how-to-print-it-c-programming">此处。不幸的是,这只能获取有关当前进程的信息。我需要的是所有正在运行的进程的 CPU 时间以及它们的 PID。
真糟糕:(
So I found out how to implement getrusage using help from here and here. The unfortunate thing is that this manages to get information only about the current process. What I need is CPU time from all the processes running and this from their PID.
Bummer :(