pileofrogs has asked for the wisdom of the Perl Monks concerning the following question:
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
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Linux Process Start Time
by idsfa (Vicar) on Jul 27, 2009 at 16:30 UTC | |
by pileofrogs (Priest) on Jul 27, 2009 at 16:41 UTC | |
Re: Linux Process Start Time
by lostjimmy (Chaplain) on Jul 27, 2009 at 17:32 UTC | |
by pileofrogs (Priest) on Jul 27, 2009 at 17:50 UTC | |
by lostjimmy (Chaplain) on Jul 27, 2009 at 19:09 UTC | |
Re: Linux Process Start Time
by ikegami (Patriarch) on Jul 27, 2009 at 16:15 UTC | |
by alexm (Chaplain) on Jul 27, 2009 at 22:33 UTC | |
Re: Linux Process Start Time
by Illuminatus (Curate) on Jul 27, 2009 at 17:11 UTC | |
by pileofrogs (Priest) on Jul 27, 2009 at 17:43 UTC | |
by Illuminatus (Curate) on Jul 27, 2009 at 18:22 UTC | |
Re: Linux Process Start Time
by Khen1950fx (Canon) on Jul 27, 2009 at 23:21 UTC | |
by pileofrogs (Priest) on Jul 28, 2009 at 17:54 UTC |