6

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?

9

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

3

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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