View Single Post
Posts: 118 | Thanked: 59 times | Joined on May 2007
#1
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!
 

The Following 3 Users Say Thank You to RobbH For This Useful Post: