Subject: | proc::proctable skips process entry |
Hi,
I am using Proc::Proctable-0.38 (was using 0.34 earlier) module to monitor a particular process. If the process is not running, I restart it or if the configuration file of the process is newer than the start time of process, I restart it.
Here is the code:
#!/opt/default/bin/perl
use strict;
use Time::Local;
use Proc::ProcessTable;
use Getopt::Std;
my %opts;
if (! getopts("v",\%opts)) {
print "Usage: checkdnsproxy.pl [-v]\n";
exit 1;
}
my $dnsproxycmd = "/opt/dnsproxy-9.2.1/sbin/dnsproxy";
my $restart=0;
my $pid=0;
my $start=0;
# make sure there is a dnsproxy process running
my $table = new Proc::ProcessTable;
my @pstable = @{$table->table};
foreach my $p ( @pstable ) {
print $p->pid,"\t",$p->cmndline,"\n" if $opts{'v'};
next unless ($p->cmndline =~ /^$dnsproxycmd\s/o);
$pid=$p->pid;
$start = $p->start;
last;
}
&restart("No running process found") unless ($pid);
my @f=stat("/opt/dnsproxy-9.2.1/etc/dnsproxy.conf");
if ($f[9] >= $start) { &restart("Newer config file found") };
sub restart {
my ($reason)=@_;
print STDERR "starting dnsproxy: $reason\n";
system("killall dnsproxy") if ($pid);
system("/etc/local/init.d/dnsproxy.sh start");
exit 0;
}
This code works fine about 90% of the times, but other times it restarts the dnsproxy even thought it was running earlier with the reason "no process found". The OS I am running is freebsd-4.3 and freebsd 4.4. Both of them have the problem. I have noticed, it happens mostly when machine has about 250+ processes. Also what's interesting is that killall aslo does not kils the existing process (lloks like that also does not finds it). So when I check the machine, the old process since last time is found to be running. This program is run through a cronjob, BTW.
Thanks for any information.