*BSD News Article 68107


Return to BSD News archive

Path: euryale.cc.adfa.oz.au!newshost.anu.edu.au!harbinger.cc.monash.edu.au!news.cs.su.oz.au!metro!metro!munnari.OZ.AU!news.ecn.uoknor.edu!solace!nntp.uio.no!news.cais.net!nntp.crosslink.net!news.magicnet.net!tarpit.thrush.com!usenet
From: rd@mail.thrush.com (R.D. Thrush)
Newsgroups: comp.unix.bsd.bsdi.misc
Subject: Re: FTPD hangs
Date: 09 May 1996 18:17:29 GMT
Organization: Thrush Consulting
Lines: 99
Message-ID: <RD.96May9141729@mail.thrush.com>
References: <4mqd5c$4be@hops.entertain.com>
NNTP-Posting-Host: localhost.thrush.com
To: dwatson@abwam.com (Darryl Watson)
In-reply-to: dwatson@abwam.com's message of 8 May 1996 15:04:12 GMT

>>>>> "dwatson" == Darryl Watson <dwatson@abwam.com> writes:
dwatson> I have been running with BSDi 2.0 with patches, and lately
dwatson> been having a problem with ftpd.

dwatson> I find that I have to clear out swapped out ftpd's every day,
dwatson> even though I have '-t 15 -T 120' in the /etc/inetd.conf for
dwatson> ftpd.

dwatson> Has anyone seen this problem?  If so, what did you do (if
dwatson> anything) to fix it?

  I've been using the attached script out of cron once an hour on a
bsdi 1.1 system for the past several months.  You'll need to adjust it
to suit your criteria/policy.

#! /usr/local/bin/perl

# Kill any ftpd that was started more than n hours ago and is
# in IW state.

$min_threshold=60;      # How old (minutes) an ftpd process can be
@mn = ('Jan','Feb','Mar','Apr','May','Jun',
       'Jul','Aug','Sep','Oct','Nov','Dec');
foreach $arg (@ARGV) {
    $debug=1 if $arg eq '-d';
    $verbose=1 if $arg eq '-v';
}
if ($debug) {
    open(PS, "<& STDIN") || die "Can't open debug file: $!";
    $_ = <PS>;
    (undef,$min,$hour) = split;
} else {
    $logfile="/var/log/ftpd.idle.log";
    open(PS, "ps axo user,pid,start,state,ucomm,time |")
        || die "Can't invoke ps: $!";
    (undef,$min,$hour) = localtime(time);
}
$now=sprintf("%02d%02d", $hour, $min);
while(<PS>) {
    ($user,$pid,$start,$state,$ucomm)=split;
    if($ucomm =~ /ftpd/ && $state=~ /^I/) {
        $ampm=substr($start,-2,2);
        if ($ampm =~ /AM|PM/) {
            if ($start =~ /^(\d+):(\d+)[AP]M$/) {
                ($h,$m)= ($1,$2);
                $h += 12 if $ampm eq 'PM';
                $then=sprintf("%02d%02d", $h, $m);
                $diff =  $now - $then;
                $diff += 2400 if $diff < 0;
                if ($diff >= $min_threshold) {
                    $pids{$pid}=$_;
                    $diff{$pid}=$diff;
                }
                next;
            }
        }
        $pids{$pid}=$_;
        $diff{$pid}=9999;
    }
}
close PS;

foreach $pid (keys %pids) {
    $killcnt++;
    push(@kills, $pid);
}
if ($verbose) {
    if ($killcnt) {
        print "Killing";
        foreach $pid (@kills) { print " $pid"; }
        print "\n";
    }
}
exit(0) unless $killcnt;
if ($debug) {
    open(MAIL, ">&STDOUT") || die "Can't append to stdout: $!";
} else {
    open(MAIL, ">>$logfile") || die "Can't append to $logfile: $!";
}
print MAIL &timestamp, ":\n";
foreach $pid (keys %pids) {
    $age=sprintf("%8.2f", $diff{$pid}/100.);
    print MAIL "Age=$age: $pids{$pid}";
    unless ($debug) {
        $killed = kill 9, $pid;
        print MAIL "Unsuccessful kill\n" unless $killed;
        $exitcode=1;
    }
}
close MAIL;
exit $exitcode;
sub timestamp {
    my($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) =
        localtime(time);
    sprintf("%.3s %2d, %4d %2d:%02d:%02d", $mn[$mon], $mday, $year+1900, $hour, $min, $sec);
}

-- 
Bob Thrush rd@thrush.com    407 425-4845/ FAX 841-8004