Greetings, fellow Monks.

I'm trying to write a script to check how long a process has been running. I can munge the output of ps, which sucks, I can read /proc/$PID/stat and find the number of jiffies, whatever they are, since the system booted, which also sucks, but in a different way. Specifically, munging ps output is unportable, unpredictable and is smells funny. Reading /proc/$PID/stat sounds great in principle, but I have fears I would do it wrong (what's a "jiffy?").

Does anyone know a perl module that will do this without sucking? (Parsing output of ps sucks. Something that reads /proc and works does not suck. Something that calls a C library OS interface function does not suck at all.)

The eventual purpose of all this is to have a simple script that exits true if a script is older than a value. So I can easily write shell scripts to kill processes that have wandered off and have been running way too long. So, if anyone knows a way to solve that problem, that would also be welcome.

UPDATE

Here's an example: Say I have two servers and I like to keep them in sync with an rsync job that runs every 10 minutes. If I run this and I find an rsync job already running*, if it's 11 minutes old, I might want to let it finish and try again in another 10 minutes. If it's a day old, I definitely want to kill it and launch a new rsync job right now.

*we assume I've filtered out any unrelated rsync processes

Thanks!
--Pileofrogs


In reply to Linux Process Start Time by pileofrogs

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.