I need a way to kill all the processes used in the script below. I removed all the unnecessary code and made it as simple as I can, without ruining the structure.
I made the kill_other
function for that, which when called (after CTRL + C
is pressed) is suppose to kill everything.
Right now if I kill the script, functionOne
and adb logcat
continue running.
How can I kill them?
Also, since I'm fairly new to the trap
function I have to ask have I positioned it correctly in the code?
EDIT : I am running this script on Ubuntu 19.04 and my target is an Android phone, if someone needs the info.
#!/bin/sh
kill_other(){
## Insert code here to kill all other functions
exit
}
trap 'kill_other' SIGINT
main(){
functionOne &
adb logcat > log_test.log &
while true
do
echo "==================================================================="
memPrint
sleep 10
done
}
functionOne(){
while true
do
sleep 20
echo "==================================================================="
echo "Starting app 1"
echo "==================================================================="
functionTwo
sleep 20
echo "==================================================================="
echo "Starting app 2"
echo "==================================================================="
functionThree
done
}
functionTwo(){
adb shell monkey -p com.google.android.youtube -c android.intent.category.LAUNCHER 1
}
functionThree(){
adb shell monkey -p tv.twitch.android.app -c android.intent.category.LAUNCHER 1
}
memPrint(){
adb shell dumpsys meminfo | grep -A 10 "Total PSS by process\|Foreground\|Perceptible\|Total RAM\|Home"
}
## Start
main