Operating System - HP-UX
1839263 Members
4224 Online
110137 Solutions
New Discussion

Re: Finding processes running too long

 
Brenda G Follin
Occasional Advisor

Finding processes running too long

I need to know if it is possible to determine if a process is running too long (3 days) and be able to kill the process. This is something that I need to use for oracle processes only.
2 REPLIES 2
A. Clay Stephenson
Acclaimed Contributor

Re: Finding processes running too long

Generally I do not suggest that this process to be automated because it could be perfectly normal for some jobs to run this long or longer. I always prefer direct intervention and moreover, waiting 3 days to kill runaway process isn't very good system management either.

In any event, I will get you started. You need to assert the XPG4 behavior of the ps command by setting the UNIX95 environment variable:

This should list all the processes owned by oracle, the PID, and the elapsed time. A little more awk or Perl and you should be good to go (although I still think this idea is dangerous and/or dumb):

#!/usr/bin/sh

typeset PID=""
typeset COMM=""
UNIX95= ps -U oracle -o comm,pid,etime |\
awk '{split($3,a,"-"); if (a[1] + 0 >= 3) {print $1,$2}}' | \
while read COMM PID
do
echo "Command: ${COMM} PID: ${PID}"
done

Put in your kills (and do not use kill -9 ${PID} and you should be good to go); you probably want to read a list of commands not to kill and filter those out but that is left for you to complete.

If it ain't broke, I can fix that.
Brenda G Follin
Occasional Advisor

Re: Finding processes running too long

Thanks for thee quick response, that is what I needed.