Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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
add comment

2 Answers 2

up vote 5 down vote accepted

I've done something like this in the past.

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

returns

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
1  
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
add comment

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

share|improve this answer
add comment

Your Answer

 
discard

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.