KILLING OLD UNIX PROCESSES
0
Q:
KILLING OLD UNIX PROCESSES
# I want to be able to extract all the oracleprod processes which are 3 days old and kill them.
Are there other date functions or methods can I use?
I can make a list of processes but how do I compare the date to kill those processes more than 3 days old.
This problem is occurring even though I have a regular cron job which kills sessions older than 2 days old in oracle. I am using 8.1.7.4 and Solaris 8.

This is where I got stuck.
curday=`date +%d`
month=`date|cut -d' ' -f2`
echo $month $curday
ps -ef|grep oracleprod | tr -s " " : | cut -d: -f3,6,7
ASKED: Aug 4 2004  10:39 AM GMT
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
0
0 pts.
0
A:
 RATE THIS ANSWER
0
Click to Vote:
  •   0
  •  0
  • AddThis Social Bookmark Button
Hi, one way to solve your problem is to use the "etime" format option of the "ps" command. This option shows the elapsed time since the process was started, in the nice form: [[dd-]hh:]mm:ss

So, the following line will return the list of "oracleprod" processes that have been running for over 1 day[*], sorted by number of running-days (decreasing).

ps -A -o user,pid,etime | grep oracleprod | grep "-" | cut -b1-17 | sort -r -k3

From here I think it is easier to obtain a list of the processes that have been running for over N days. Hope this helps.

[*] Using "etime", the output lines having the "-" character imply that "dd" is at least 1 => process is running for at least 1 day.
Try it by running the line:
ps -A -o user,pid,etime | grep oracleprod
Last Answered: Aug 4 2004  12:43 AM GMT by voltaire   0 pts.
0
0
Discuss This Answer:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _



_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

voltaire   0 pts.  |   Aug 5 2004  12:07PM GMT

(yesterday I was a bit in a hurry…)

This will give you exactly the list of all oracleprod processes running for 3 or more days (respect the spaces embedded in the egrep expression):

ps -A -o user,pid,etime | grep oracleprod | egrep -v ” 1-| 2-”

or, if you want only the list of PIDs:

ps -A -o user,pid,etime | grep oracleprod | egrep -v ” 1-| 2-” | cut -c10-15

 
0