views:

61

answers:

2

Hello Everyone!

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

A: 

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. :)

John Zwinck
@John. Could you expand on that? Maybe point me in a direction of how exactly I would do what you are saying?
Eric Brotto
Eric Brotto: On a Linux-based OS, every process is represented by a file, named for the process's PID, on the /proc file system. On Mac OS X, there is no /proc file system (not built in, anyway—I think there's a third-party one available).
Peter Hosey
A: 

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 :(

Eric Brotto
Are you actually interested in the CPU usage of every process separately, or do you only care about CPU usage of the whole system overall?
Peter Hosey
@Peter I'm interested in the former: "the CPU usage of every process separately" as seen when you call top from command line.
Eric Brotto