Question says it all on the tin. Can someone explain to me what goes on here ? I'm trying to find out how to background a process in a script that calls another function and reliably terminate it when ready. Wondering whether I will have to move it all into one function ?
function dosomething {
while :
do
printsomething "doing something"
done
}
function printsomething {
echo $@
}
function otherfunction {
dosomething &
TMP_PID=$!
}
function killsomething {
quit_test=`ps -p "$TMP_PID" | sed '1d' | awk '{print $1}'`
if [ "$quit_test" != "" ] ; then
(kill $TMP_PID >/dev/null)
fi
}
## MAIN
TMP_PID=""
echo "starting program"
otherfunction
sleep 5s
killsomething