Improving the stability of the TCPSClient

This script is quite helpful when you want to run the TCPSClient (beta 3) somewhat completely unattended.

If the program hangs up, fails or anything doesn’t work as expected the CPU load increased drastically. This is taken as an indicator and the TCPSClient will be terminated and restarted.

!/bin/bash
PROCESSNAME=TCPSClient.bin
CPU_USAGE_THRESHOLD=1010
declare -i MULTIPLIER=10

killall -v $PROCESSNAME
sleep 3
while true; do
	if ps ax | grep -v grep | grep TCPSClient > /dev/null 
	then
		CPU_TEMP_USAGE=$(top -bn1 |grep TCPSClient | awk -F' ' '{print $9}')
		CPU_USAGE=$(echo "scale=2;$CPU_TEMP_USAGE*$MULTIPLIER"|bc)
		CPU_INT=${CPU_USAGE%.*}
		if [ $CPU_INT -gt $CPU_USAGE_THRESHOLD ] ; then
			echo KILLING
			killall -v $PROCESSNAME
			sleep 3
		fi
	else
		/home/pi/TCPSClient/TCPSClient.bin &
		sleep 3
	fi
done

 

This is one of the very few Linux scripts I did. Be gentle. Feel free to contact me if there are questions, suggestions, etc.

Tagged , , , .Speichere in deinen Favoriten diesen permalink.

Kommentare sind geschlossen.