Script-for-GUI-cron-control-oom: Difference between revisions

From VoIPmonitor.org
Jump to navigation Jump to search
(Created page with " #!/bin/bash #verbose 0=none 1=logfile verbose='1' logfile='/root/script/check_php.log' #logfile='/dev/stdout' #limit is in kB (100000=100MB, 5000000=5GB) prcL=5000000...")
 
No edit summary
 
(One intermediate revision by the same user not shown)
Line 20: Line 20:
   scV=$(cat $scP)
   scV=$(cat $scP)
   rundate=$(date)
   rundate=$(date)
   if [ "9$prcM" \> "9$prcL" ]; then
   if [ "9$prcM" -gt "9$prcL" ]; then
         if [ "$verbose" -ge "1" ]; then
         if [ "$verbose" -ge "1" ]; then
                 echo "$rundate Zabit PID:$prc" >> $logfile
                 echo "$rundate set oom_adj_score=$oom_adj_score for PID:$prc" >> $logfile
                 echo "            Mem VSize $prcM Kb a limit je $prcL Kb" >> $logfile
                 echo "            Mem VSize $prcM Kb limit is $prcL Kb" >> $logfile
                echo "            OOM score $scV set to $oom_adj_score" >> $logfile
                 detail=$(ps -q $prc -eo pid:16,cmd:50,etime:20)
                 detail=$(ps -q $prc -eo pid:16,cmd:50,etime:20)
                 echo "$detail" >> $logfile
                 echo "$detail" >> $logfile

Latest revision as of 18:23, 6 February 2020

#!/bin/bash
#verbose 0=none 1=logfile
verbose='1'
logfile='/root/script/check_php.log'
#logfile='/dev/stdout'

#limit is in kB (100000=100MB, 5000000=5GB)
prcL=5000000

#oom_score_adj to set when process over limit
oom_adj_score=1000

#list of processes
prcs=$(pgrep php) 
for prc in $prcs; do
 prcM=$(cat /proc/$prc/status|grep VmSize| cut -d ':' -f2|rev|cut -d ' ' -f2|rev|xargs)
 prcP="/proc/$prc"
 prcC=`cat $prcP/cmdline`
 scP="$prcP/oom_score_adj"
 scV=$(cat $scP)
 rundate=$(date)
 if [ "9$prcM" -gt "9$prcL" ]; then
       if [ "$verbose" -ge "1" ]; then
               echo "$rundate set oom_adj_score=$oom_adj_score for PID:$prc" >> $logfile
               echo "             Mem VSize $prcM Kb limit is $prcL Kb" >> $logfile
               detail=$(ps -q $prc -eo pid:16,cmd:50,etime:20)
               echo "$detail" >> $logfile
               echo >> $logfile
       fi
       echo $oom_adj_score >> $scP
  fi
done