#!/bin/bash
#clean up dbus-monitor instances
pList=`ps h c --ppid 1 -o pid`
N=0
cleanList=""
for aPid in ${pList} ; do
#	echo "aPid is ${aPid}"
	aLine=`ps h c -p ${aPid}`
#	echo "aLine is ${aLine}"
	echo "${aLine}" | egrep -e 'dbus-monitor' >/dev/null 2>/dev/null
	found=$?
	if [ ${found} -eq 0 ]; then
		if [ ${N} -eq 0 ]; then
			cleanList="${aPid}"
		else
			cleanList="${cleanList} ${aPid}"
		fi
		N=$((N+1))
	fi
done
#clean up namedPipe.sh instances
pList=`ps h --ppid 1 -o pid`
for aPid in ${pList} ; do
	aLine=`ps h -p ${aPid}`
#	echo "aLine is ${aLine}"
	echo "${aLine}" | egrep -e 'namedPipe.sh' >/dev/null 2>/dev/null
	found=$?
	if [ ${found} -eq 0 ]; then
#		echo "aPid is ${aPid}"
		if [ ${N} -eq 0 ]; then
			cleanList="${aPid}"
		else
			cleanList="${cleanList} ${aPid}"
		fi
		N=$((N+1))
	fi
done
#echo "cleanList is ${cleanList}"
for aPid in ${cleanList} ; do
	kill ${aPid}
done

