Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Killing old processes

Status
Not open for further replies.

lhg1

IS-IT--Management
Mar 29, 2005
134
DK
Hi

I have a 3. part software that is leaving processes on the system.

I can easyly find the processes, becourse there should be any thats over 5 minutes old.

Is there a command to kill all processes thats over 5 min old?

Something like this but where only those over 5 min are captured
Code:
kill `ps -ef|grep sftp-server|awk '{print $2}'`

Thanks
LHG
 
Try this:

Code:
ps -eo pid,etime,args | awk '
    /sftp-server/ { 
         etime=$2
         gsub("[-:]+","",etime)
         if (etime > 500) { print $1 }
    }
' | xargs echo kill

Take out the echo when you're satisfied that it's going to kill the right processes.

Basically it pulls out the ETIME (elapsed time since process started) field, which is in days-hh:mm:ss syntax, strips out the punctuation, pretends it is a decimal number and prints out those that have been running for more than 500 units (i.e. 5 minutes).

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top