Pacific-Design.com

    
Home Index

1. Bash

2. Processes

Bash / Processes /

Controler of forked processes

#!/bin/bash -x
#---------------------------------------------------------------------------------------------------------------#
sleep $(( $$ % 50 ))
#---------------------------------------------------------------------------------------------------------------#
ps -eo pid,etime,args | grep mapper.pl | perl -ane '($h,$m,$s)=split /:/,$F[1]; system("kill -9 $F[0]") if ($h > 50);'
ps -eo pid,etime,args | grep curl      | perl -ane '($h,$m,$s)=split /:/,$F[1]; system("kill -9 $F[0]") if ($h > 0);'
ps -eo pid,etime,args | grep lynx      | perl -ane '($h,$m,$s)=split /:/,$F[1]; system("kill -9 $F[0]") if ($h > 0);'
ps -eo pid,etime,args | grep ots       | perl -ane '($h,$m,$s)=split /:/,$F[1]; system("kill -9 $F[0]") if ($h > 0);'
#---------------------------------------------------------------------------------------------------------------#
stop_mapper()
{
  proc=""
  for line in `ps -eo pid,etime,args --sort etime | grep perl | grep -v grep | awk '{ print $1, $2 }'` 
  do

   if [ ${#line} -gt  7 ]
   then
      echo "-----" $proc $line "----"
      kill -9 $proc
      sleep 1  
   fi
   proc=$line
   echo $line
  done
}
#--------------------------------------------------------------------------------------------------------------#
UPTIME=`uptime | awk -F 'load average: ' '{print $2}' | awk -F '.' '{print $1}'`;
echo "Uptime = " $UPTIME
if [ $UPTIME -ge 7 ]; then
    killall mapper.pl 
    sleep 1  
    crontab /home/spider/jobs/crontab2 
fi
#--------------------------------------------------------------------------------------------------------------#
#stop_mapper
#--------------------------------------------------------------------------------------------------------------#