Reputation: 11
I really need help here... I am writing a shell script, which starts a process then kills it every 10 seconds then restarts it again.
I understand that using 'ps' command will show all the processes that are running and you can kill it by running 'kill [pid]'. However, grepping the PID of the process that I am launching is not easy.
I've looked everywhere and for some reason, I cannot use functions like pgrep, awk, xargs, pidof... They are just not found...
I can only think of a way where I have to output the ps file then parse it and grab the PID alone.. but that seems too much...
Can anyone help me? I think I am only limited to using ps and grep only...
I am launching the phone application by running am start -a android.intent.action.CALL -d tel:XXX-XXX-XXXX Then by running 'ps m.android.phone' I can use kill [PID] to stop call the call
I've also tried running commands like pm clear com.android.phone, adb shell am force-stop com.android.phone but none of them would stop the call...
Please help Thanks a lot!
Upvotes: 1
Views: 4871
Reputation: 1501
following what marcus said:
adb shell kill -9 $(adb shell ps | grep firefox | awk '{print $1}')
Upvotes: 0
Reputation: 41450
You could try the command pidof
to get the process id directly, eks:
pidof apashe2
Upvotes: 0
Reputation: 69238
Use
am kill package-name
or
am force-stop package-name
replacing package-name by the name of the application you want to kill.
Upvotes: 2
Reputation: 618
If you know the process name of the application, then I wrapped together a very quick and dirty script to parse the PID of the process:
ps -u $(whoami) | grep firefox | awk '{printf $1}'
You should obviously replace firefox with your process name of choice.
Please note that I am no expert on the area, but it works on my end.
Upvotes: 1