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.


In reply to Re: Calculating percent cpu in linux? by scmason
in thread Calculating percent cpu in linux? by suaveant

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.