Getting the CPU usage in a generic way across OSes

Fernando Perez fperez528 at yahoo.com
Mon Jun 16 17:35:59 EDT 2003


Kristoffer Erlandsson wrote:

> Hello,
> 
> I am writing an application that, among other things, should monitor the
> CPU usage. However, this seems impossible to do in a platform
> independant way. I have browsed the source from some C-programs which do
> this and they all seem to depend on very different ways depending on
> what OS the program is running on. Many of the ways use system specific
> system calls (which I can't find Python functions for). The only
> solution I have come up with so far is to extend python with some C-code
> which get the CPU usage for me. But this is of course more tedious than
> I'd like it to be. So I'm wondering if a module implementing this
> allready exists? I've had a date with google for this one, but no luck.
> If it doesn't exist, do anyone have a better idea than to write/rip the
> C-code implementing this for different OS:es? I'm only interested in
> doing it for *nix OS:es.
> 
> I'm very grateful for any help on this.
> 
> Regards,
> Kristoffer Erlandsson

As long as you are using *nix, why not use resource.getrusage?

http://www.python.org/doc/current/lib/node275.html

Best,

f




More information about the Python-list mailing list