Question

  Asked: Aug 4 2004   10:39 AM GMT
  Asked by: geoffreyhalleds


KILLING OLD UNIX PROCESSES


Unix, Unix servers, Unix tools, Awk, Bash, Bison, Bourne, CSH, Grep, KSH, nroff, Procmail, sed, xargs, Unix versions, Solaris

# 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

Subscribe to Alerts! Get questions and answers delivered to your Inbox.


E-mail me updates on this question



   SUBSCRIBE

hidden modal window

Answer Wiki (Improve, edit or add to this answer)


 RATE THIS ANSWER
0
Click to Vote:
  •   0
  •  0



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
  • AddThis Social Bookmark Button

Browse more Questions and Answers on Linux, DataCenter and Exchange.

Looking for relevant Linux Whitepapers? Visit the SearchEnterpriseLinux.com Research Library.


Discuss This Answer


You must be logged-in to discuss a question. Log-in/Register

voltaire  |   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