track cpu usage of linux application

Zed A. Shaw zedshaw at zedshaw.com
Mon May 14 15:18:05 EDT 2007


On Mon, 14 May 2007 20:56:20 +0000
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?

Look at the /proc filesystem instead.  For example, you can do this:

cat /proc/49595/status

To get information about that process.  Using this you can find out
anything you need with just basic file operations.

Use: man proc to find our more.

-- 
Zed A. Shaw
- Hate: http://savingtheinternetwithhate.com/
- Good: http://www.zedshaw.com/
- Evil: http://yearofevil.com/



More information about the Python-list mailing list