Getting the CPU usage in a generic way across OSes

Kristoffer Erlandsson krier115 at student.liu.se
Mon Jun 16 23:53:31 CEST 2003


On Mon, 16 Jun 2003 at 21:35 GMT, Fernando Perez wrote:
> 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

I'm sorry, I maybe was a bit unclear in my first post. I want to monitor
the _system wide_ cpu usage, as found for example in /proc/stat on some
systems. resource.getrusage doesn't seem to help me do that. Thank you
for your reply, and sorry for my unclearness.

Regards,
Kristoffer Erlandsson





More information about the Python-list mailing list