Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Linux Process Start Time

by Illuminatus (Curate)
on Jul 27, 2009 at 17:11 UTC ( [id://783602]=note: print w/replies, xml ) Need Help??


in reply to Linux Process Start Time

While it would be nice to have a simple command that gives you the information you want, I disagree that parsing the output of ps is 'unportable'. It is certainly far more portable than /proc. The POSIX(ie SYSV) options for ps have been standardized for quite some time, as have the BSD options. Most systems I have worked with (AIX, Solaris, Linux, HP-UX) support the POSIX options. The only one that would require different syntax is FreeBSD.

You might try just keeping track of PID and procname between calls to your monitor. Using 'ps -ex | grep 'name1|name2|...' should give you what you want with either a POSIX or BSD ps(pid will always be first field). If the same PID/procname shows up twice in a row, kill it off. Just a thought...

fnord

Replies are listed 'Best First'.
Re^2: Linux Process Start Time
by pileofrogs (Priest) on Jul 27, 2009 at 17:43 UTC

    I've had the output of ps change on me in a distro version update. But, actually, you're probably right, I wasn't using a POSIX or BSD output format. That would stabilize it.

    And yes, /proc isn't portable. It might be a little bit portable. I know it's optional on OpenBSD, for instance.

    Looking for the same process name twice won't help. I want to know the age. I think I'll add an example to the OP.

    Good point about POSIX or BSD ps output.

    --Pileofrogs

      Sorry, I should have been clearer. Let's say you run the monitor in cron every 10 minutes:
      • try to open /tmp/monitor_info
      • if non-existent, generate pid/procname list, write to /tmp/monitor_info and exit
      • read file data into array/hash
      • generate pid/procname list using aforementioned ps command
      • compare lists. If same pair shows up in both, kill it (it's been running longer than 10 minutes).
      • write new list to /tmp/monitor_info
      Adjust cron interval to be a time comfortable to ensuring that process is broken. It is a little more complicated if you have processes that have different 'comfort intervals', but you could simply include a count to each line in /tmp/monitor_info to manage this.

      This script is short and easy. Does that make sense?

      fnord

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://783602]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-04-19 21:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found