Do you know where your variables are? | |
PerlMonks |
Linux Process Start Timeby pileofrogs (Priest) |
on Jul 27, 2009 at 16:03 UTC ( [id://783581]=perlquestion: print w/replies, xml ) | Need Help?? |
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!
Back to
Seekers of Perl Wisdom
|
|