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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Evaluate process hung more than x sceonds

Status
Not open for further replies.

ryanc2

MIS
Apr 18, 2003
73
0
0
US
I need an expression to identify hung ftp processes that are older than "n" number of seconds.

In my script I have found the PID and STIME of the process that is hung. I would like to compare that to current time (HH:MM:SS and kill if it is older than 90 seconds).

Any help would be appreciated.

Thanks...
 
Hi ryanc2,

There must be better ways to do this but it should work.

-----------------------
#!/bin/ksh

time2=`date | awk '{print $4}'` #current time

h1=`echo $time1 | cut -d: -f1`
m1=`echo $time1 | cut -d: -f2`
s1=`echo $time1 | cut -d: -f3`
h2=`echo $time2 | cut -d: -f1`
m2=`echo $time2 | cut -d: -f2`
s2=`echo $time2 | cut -d: -f3`

let totalsecs1=${h1}*3600+${m1}*60+${s1}
let totalsecs2=${h2}*3600+${m2}*60+${s2}
let difference=$totalsecs2-$totalsecs1

[ $difference -gt 90 ] && kill $PID

------------------------

This assumes that you have a variable time1 containing the start time of the ftp and a variable PID containing the PID.

If you have more than 1 process to deal with then you'll need a loop.

Matt.
 
This is a bit tidier ..

-----------------------
#!/bin/ksh

time2=`date | awk '{print $4}'` #current time

totalsecs1=`echo $time1 | awk -F: '{val=$1*3600+$2*60+$3; print val}'`
totalsecs2=`echo $time2 | awk -F: '{val=$1*3600+$2*60+$3; print val}'`
let difference=$totalsecs2-$totalsecs1

[ $difference -gt 90 ] && kill $PID

Matt.

---------------------------
 
May not work in all instances because there is no way of checking if the ftp started on a different day.

If the ftp starts at 23:59:02 and the script runs after midnight then it will be another 24hrs nearly before it kills it. No way roud this as far as I can see because STIME doesn't give the date.

Matt.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top