#!/usr/local/bin/perl
$_ = `date`;
($month,$day,$hour,$min) = /^\w+\s(\w+)\s+(\d+)\s+(\d+):(\d+):.*$/;
#print "month=$month day=$day hour=$hour min=$min\n";
foreach $_ (`ps -ef|egrep 'I|W|S|D'|egrep -v ps|egrep 'load|sqlplus|now|wow|home|oraclemerlin|inc.pl'`) {
#print;
($pid,$phour,$pmin,$command) = /^oracle\s+(\d+).*\w*\s+(\d\d):(\d\d):\d\d\s+.*\s+(.*)$/;
#($pid,$phour,$pmin,$command) = /^oracle\s+(\d+).*IW\w*\s+(\d\d):(\d\d)\s+.*\s+(.*)$/;
#print "($pid,$phour($hour),$pmin($min),$command)\n";
if ($pid eq '') {
        ($pid,$pmonth,$pday,$command) = /^\S+\s+(\d+).*IW\s+(\w+)\s+(\d+)\s+.*\s+(.*)$/;
        if ($day ne $pday) {
                #print "2 pid=$pid pmonth=$pmonth pday=$pday command=$command\n";
                system("kill -9 $pid");;
                #print "### $pid killed ###\n";
        }
}
else {
        $diff = ($hour-$phour)*60+$min-$pmin;
        #print "diff = $diff\n";
        if ( $diff >= 20) {
                #print "pid=$pid phour=$phour command=$command\n";
                system("kill -9 $pid");;
                #print "### $pid killed ###\n";
        }
}
}
exit;

