#!/bin/bash log=/tmp/cin_slow.log limit_cpu=60.0 limit_slow=6 pid=`pgrep -x cinnamon` top=`top -b -n1 | grep -w $pid` cpu=`echo $top | egrep -v '-' | awk '{ print $9; }'` state=`echo $top | egrep -v '-' | awk '{ print $8; }'` debug=1 if [ $debug == 1 ]; then echo "STARTING at `date`" >> $log echo "0: cpu $cpu -- from $top" >> $log fi cnt=1 sample=1 times_slow=0 while [ $cnt -le 50 ] && [ $sample -le 10 ]; do top=`top -b -n1 | grep -w $pid` cpu=`echo $top | egrep -v '-' | awk '{ print $9; }'` if [ $debug == 1 ]; then echo "$cnt: cpu $cpu -- from $top" >> $log fi if [ $state == "R" ] || [ $cpu != "0.0" ] ; then cnt=`expr $cnt + 1` sample=`expr $sample + 1` else if [ $debug == 1 ]; then echo "$cnt: - consider this run as not relevant, seems cinammon was idle when we ran top" >> $log fi fi if [ `echo "$cpu >= $limit_cpu" | bc` = 1 ]; then times_slow=`expr $times_slow + 1` if [ $debug == 1 ]; then echo "$cnt: + We have a slow reading (so far: $times_slow from $sample)" >> $log fi fi sleep 2 cnt=`expr $cnt + 1` if [ $times_slow -gt $limit_slow ]; then break fi done if [ $debug == 1 ]; then echo "From a sample of $sample measurements, cin* was slow $times_slow times" >> $log wmctrl -l >> $log fi if [ $times_slow -gt $limit_slow ]; then export DISPLAY=:0 zenity --info --text "I think cinammon is slow! Please manually restart it" exit 0 fi