in reply to Calculating percent cpu in linux?

I am a little confused by this question, I have looked on several linux boxes (SuSe, Fedora and Mandrake) and have yet to find a '/proc/PID/' directory. In all of these machines, this info was stored under a directory bearing the pid-number in the top level of the proc filesystem (for instance, init has PID 1 and its info is located in /proc/1/)

Maybe that is what you mean. If not, and your machine actually does have a /proc/PID/* directory, then this does not seem like a very portable manner of doing it. Perhaps you should rethink using ps, as it should be very portable.

If you really want to use the 'pure perl' method, then you will not reinvent the wheel. Look here at Proc::ProcessTable from... you guessed it CPAN. It will do everything you need.

Good luck.

Replies are listed 'Best First'.
Re^2: Calculating percent cpu in linux?
by suaveant (Parson) on May 03, 2005 at 04:22 UTC
    Well.. actually this is for the Linux half of a Linux/Solaris library. I could use ps, but from years of using ps I tend not to entirely trust parsing the output.

    And there are a couple problems with Proc::ProcessTable... 1) it is mostly C, 2) I can't seem to see a way to call for individual pids in it... maybe I am reading the docs wrong, but it looks like you can only get the whole processtable as a snapshot, basically...

                    - Ant
                    - Some of my best work - (1 2 3)