track cpu usage of linux application

Fabian Braennstroem f.braennstroem at gmx.de
Tue May 15 18:39:19 EDT 2007


Hi,
    thanks to both! I will take a look at the proc files!

* James T. Dennis <jadestar at idiom.com> wrote:
> Fabian Braennstroem <f.braennstroem at gmx.de> wrote:
>> Hi,
>
>>    I would like to track the cpu usage of a couple of
>>    programs using python. Maybe it works somehow with
>>    piping 'top' to python read the cpu load for a greped
>>    application and clocking the the first and last
>>    appearence. Is that a good approach or does anyone have
>>    a more elegant way to do that?
>
>> Greetings!
>> Fabian
>
>  If you're on a Linux system you might be far better accessing
>  the /proc/$PID/stat files directly. The values you'd find therein
>  are documented:
>
> 	http://www.die.net/doc/linux/man/man5/proc.5.html
>
>  (among other places).
>
>  Of course you could write you code to look for file and fall back
>  to use the 'ps' command if it fails.  In addition you can supply
>  arguments to the 'ps' command to limit it to reporting just on the
>  process(es) in which you are interested ... and to eliminate the
>  header line and irrelevant columns of output.

Greetings!
 Fabian




More information about the Python-list mailing list