Using getrusage
As a continuation of this questio开发者_如何学JAVAn 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
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 have procfs
(at least, not standard), though, so this answer will fall into the "any help" category. :)
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 :(
精彩评论