[OS X Emacs] Re: M-x proced

David Reitter david.reitter at gmail.com
Tue Mar 9 18:26:03 EST 2010


On Mar 9, 2010, at 4:55 PM, Leo wrote:

>  
> <proced-osx.png>
> However, do you know how to get the cpu and mem percentage?
> 
> struct extern_proc.p_pctcpu always gives me '0'.


sysctl is a lower-level library than Carbon, but I can see why we don't want to include Carbon.h.

One clean way seems to be to go through getrusage(), but that is guaranteed for yourself and the child processes only.  

What about processSize from the ProcessInfoRec structure?
You can easily convert that into a percentage after querying all processes.

And to get a snapshot of the CPU usage, I would query GetProcessInformation() twice, noting processActiveTime so that you can see what the process has used in the last 0.1 second or whatever.... However, the Apple doc says "In Mac OS X, the processActiveTime field of the returned structure is always 0", so this is not an option.

So, the answer is, I don't know.  I would probably take a look at the darwin "top" source code:

http://www.opensource.apple.com/source/top/top-67/

From cpu.c it seems that it just keeps sampling  and attributes time lapsed to the active process, but I might be wrong.



-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 203 bytes
Desc: This is a digitally signed message part
URL: <http://email.esm.psu.edu/pipermail/macosx-emacs/attachments/20100309/04e52679/attachment.sig>


More information about the MacOSX-Emacs mailing list