maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Maemo 5 / Fremantle (https://talk.maemo.org/forumdisplay.php?f=40)
-   -   Script to kill runaway hildon-home processes (https://talk.maemo.org/showthread.php?t=75784)

RobbH 2011-08-15 22:54

Script to kill runaway hildon-home processes
 
First of all, I do not actually recommend that anyone use this. It hasn't made my phone blow up yet, but I have had to pull the battery on one occasion. For all I know, it might harm yours.

However, it does appear to do the job for which it's intended: catching and killing runaway hildon-home processes before they drain the N900 battery. I start it with this command:

nohup hhkill &

Code:

#!/bin/sh
#Kill runaway hildon-home processes.
#Checks processor load of hildon-home every 60 seconds, except when screen is unlocked.
#Kills hildon-home if two successive checks show load over threshhold
#Contains some leftover code from earlier version, using three successive checks, 30 seconds apart

if [ -e /home/user/hhkills-prev ] #delete backup log, if it exists
then
        rm /home/user/hhkills-prev
fi

if [ -e /home/user/hhkills ] #rename most recent log to backup, if it exists
then
        mv /home/user/hhkills /home/user/hhkills-prev
fi

echo "Start: " `date` > /home/user/hhkills #start new log

#initialize values
HH1=0
#HH2=0  #used in earlier version
HHTHRESH=50  #Threshhold: hildon-home processor loads above this value will be considered excessive
HHPAUSE=60  #Pause between cycles: the script waits this many seconds between checks

#start loop
while 'true'
do
        #shift previous values down
        #HH3=$HH2  #used in earlier version
        HH2=$HH1

        #get screen lock status
        SCRSTAT=`dbus-send --system --type=method_call --dest="com.nokia.mce" --print-reply "/com/nokia/mce/request" com.nokia.mce.request.get_tklock_mode|awk -F "\"" '/g/ {print $2}'`

        if [ "$SCRSTAT" = "unlocked" ]
        then
                HH1=0 #if the screen is unlocked, clear HH1 and do nothing else this cycle

        else
                #get processor load of hildon-home
                HHSTAT=`top -n1 | grep hildon-home | awk '{print $7}'` # | awk -F "." '{print $1}'`  #final part truncates value to integer; moved below
                #echo $HHSTAT #used while debugging: sends HHSTAT as float to stdout
                #truncate HHSTAT to integer
                HHSTAT=`echo $HHSTAT  | awk -F "." '{print $1}'`
                #compare HHSTAT to threshhold, set HH1 if above, clear it otherwise
                if [ "$HHSTAT" -gt "$HHTHRESH" ]
                then
                        HH1=1
                        echo "hh  $HHSTAT " `date` >> /home/user/hhkills #writes all above-threshhold values to log. Useful when debugging, but makes for very large log.
                else
                        HH1=0
                fi
                HHSUM=`expr $HH1 + $HH2` #+ $HH3`
                #echo $HHSUM #sometimes useful when debugging: sends sum to stdout
                #check if HH1, HH2 (and HH3 in earlier version) have all been set. If so, kill hildon-home and log the kill
                if [ "$HHSUM" -eq "2"  ]
                then
                        #kill hildon-home and log the kill
                        killall hildon-home
                        echo "Kill: " `date` >> /home/user/hhkills
                        HH1=0
                fi
        fi

        #pause before next cycle
        sleep "$HHPAUSE"

done

Comments, criticism and improvements welcome. Especially improvements!

prankster 2011-08-15 23:00

Re: Script to kill runaway hildon-home processes
 
battery drainage is more concerned with Xorg though if some one could work on that as well.nice work though and to prove that need testers .

RobbH 2011-08-27 17:26

Re: Script to kill runaway hildon-home processes
 
Quote:

Originally Posted by prankster (Post 1070787)
battery drainage is more concerned with Xorg though if some one could work on that as well.nice work though and to prove that need testers .

This is very much a case of treating the symptoms rather than trying to cure the underlying problem. But I'm happy with it, so far. Battery life has improved. (Note: all the disclaimers from the original post still apply!)

The version I'm currently using incorporates a few changes. It still checks the hildon-home load every 60 seconds, but now kills the process if two of the last three checks have reported a value over the threshhold.

Code:

#!/bin/sh
#Kill runaway hildon-home processes.
#Checks processor load of hildon-home every 60 seconds, except when screen is unlocked.
#Kills hildon-home if two of three successive checks show load over threshhold
#Contains some leftover code from earlier versions

if [ -e /home/user/hhkills-prev ] #delete backup log, if it exists
then
        rm /home/user/hhkills-prev
fi

if [ -e /home/user/hhkills ] #rename most recent log to backup, if it exists
then
        mv /home/user/hhkills /home/user/hhkills-prev
fi

echo "Start: " `date` > /home/user/hhkills #start new log

#initialize values
HH1=0
HH2=0
HHTHRESH=50  #Threshhold: hildon-home processor loads above this value will be considered excessive
HHPAUSE=60  #Pause between cycles: the script waits this many seconds between checks

#start loop
while 'true'
do
        #shift previous values down
        HH3=$HH2
        HH2=$HH1

        #get screen lock status
        SCRSTAT=`dbus-send --system --type=method_call --dest="com.nokia.mce" --print-reply "/com/nokia/mce/request" com.nokia.mce.request.get_tklock_mode|awk -F "\"" '/g/ {print $2}'`

        if [ "$SCRSTAT" = "unlocked" ]
        then
                HH1=0 #if the screen is unlocked, clear HH1 and HH2; do nothing else this cycle
                HH2=0
        else
                #get processor load of hildon-home
                HHSTAT=`top -n1 | grep hildon-home | awk '{print $7}'` # | awk -F "." '{print $1}'`  #final part truncates value to integer; moved below
                #echo $HHSTAT #used while debugging: sends HHSTAT as float to stdout
                #truncate HHSTAT to integer
                HHSTAT=`echo $HHSTAT  | awk -F "." '{print $1}'`
                #compare HHSTAT to threshhold, set HH1 if above, clear it otherwise
                if [ "$HHSTAT" -gt "$HHTHRESH" ]
                then
                        HH1=1
                        echo "hh  $HHSTAT " `date` >> /home/user/hhkills #writes all above-threshhold values to log. Useful when debugging, but makes for very large log.
                else
                        HH1=0
                fi
                HHSUM=`expr $HH1 + $HH2 + $HH3`
                #echo $HHSUM #sometimes useful when debugging: sends sum to stdout
                #check if HH1, HH2 and HH3 have all been set. If so, kill hildon-home and log the kill
                if [ "$HHSUM" -ge "2"  ]
                then
                        #kill hildon-home and log the kill
                        killall hildon-home
                        echo "Kill: " `date` >> /home/user/hhkills
                        HH1=0  #clear these values and give hildon-home a minute to restart and stabilize
                        HH2=0
                        sleep 60
                fi
        fi

        #pause before next cycle
        sleep "$HHPAUSE"

done



All times are GMT. The time now is 09:24.

vBulletin® Version 3.8.8