Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I know that I can do ps aux | grep cgi to get a list of all cgi scripts currently running, and ps -p [pid] -o etime= can get me the run time for each pid; is there a way to combine the two, or better still, only return those that have been running for "too long" (say, 45sec)?

Ideally, I'm looking for something that could be put into a perl script that looks out for issues, emails me the details and pro-actively kills the process "for safety". would it be better to just strap a the output from one, and then iterate through the results?

share|improve this question
up vote 6 down vote accepted

I've done something like this in the past.

ps -A -o etime,pid,user,args| grep init


180-04:55:20    1 root     init [5]

Which is easily parse-able in perl. I used split and pop to parse it.

The format is [[dd-]hh:]mm:ss

share|improve this answer
Honestly, I would use search.cpan.org/~durist/Proc-ProcessTable-0.45/ProcessTable.pm . The above scenario was done in a unix environment where installing perl modules was 'expensive' – user606723 Jul 20 '11 at 21:45

Instead of this you might run monit, which as designed for this already.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.