#!/bin/sh
MMAX=4956 #strict

while :; do
	# do not kill gpsdriver if gps is in use
	if [ ! "$(pidof gpsd)" ]&&[ ! "$(pidof minigpsd)" ]; then
		PID=$(pidof gpsdriver)
		if [ "$PID" ]; then
			KILL=$(busybox awk -v MMAX="$MMAX" '($1 == "VmSize:") {if ($2>MMAX) print 1}' /proc/$PID/status) 2>/dev/null
			[ "$KILL" ]&&kill $PID&&echo $(date) killed gpsdriver pid=$PID
		fi
	fi
	sleep 1800
done
