I am building an Android app for RAM optimization. I can successfully get the list of running processes (and their PIDs) using this answer. However, I don't see a way to kill them or their background services by PID.
The jobs command will show any background jobs started within the current shell, usually by starting a background task with the & operator or ^Z bg (e.g. sleep 10 & ). If you want to see all of the background processes running on the system, you can use ps -e , or ps -eF to get some additional details.
To list currently running processes, use the ps , top , htop , and atop Linux commands. You can also combine the ps command with the pgrep command to identify individual processes.
Killing a background process is fairly straightforward; use the command pkill and the process ID, or process name as: Using the pkill command will force terminate (-9) the processes with the process name of ping.
It turned out to be something very basic:
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
for (RunningAppProcessInfo pid : am.getRunningAppProcesses()) {
am.killBackgroundProcesses(pid.processName);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With