track cpu usage of linux application

  • Thread starter Fabian Braennstroem
  • Start date
F

Fabian Braennstroem

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
 
J

James T. Dennis

Fabian Braennstroem said:
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.
 
F

Fabian Braennstroem

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

* James T. Dennis said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top