By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,400 Members | 903 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,400 IT Pros & Developers. It's quick & easy.

track cpu usage of linux application

P: n/a
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

May 14 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Fabian Braennstroem <f.************@gmx.dewrote:
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.
--
Jim Dennis,
Starshine: Signed, Sealed, Delivered

May 14 '07 #2

P: n/a
Hi,
thanks to both! I will take a look at the proc files!

* James T. Dennis <ja******@idiom.comwrote:
Fabian Braennstroem <f.************@gmx.dewrote:
>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

May 15 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.