Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List of All running processes in Android

How to get the list of Android system's All running process including System launched processes?

I tried to get the list using below code:

ActivityManager activityManager = (ActivityManager) this.getSystemService( ACTIVITY_SERVICE );
List<RunningAppProcessInfo> procInfos = activityManager.getRunningAppProcesses();

This gave me the List of processes such as com.android.phone, com.android.chrome, etc.

But when I run a ps command in my adb shell, I could see whole other bunch of processes running. I am attaching the screenshot of all those processes running in my system. Running processes in my devices

As one can see, there are several Android System's processes are also running like /system/bin/vold and /system/bin/installed, etc.

However, these are not reported by getRunningAppProcesses() API. In its docs, it says that this API:

Returns a list of application processes that are running on the device.

Does this mean it won't return "system process"? And if that is the case what option developer can have to iterate over "ALL" process running on Android?

-- What else I tried: Tried with 2 more APIs from ActivityManager:

  1. getRecentTasks(int maxNum) and it's variant.

But Android docs warns about its use as below:

This method was deprecated in API level 21.

As of LOLLIPOP, this method is no longer available to third party applications

  1. getRunningServices(int maxNum)

But both of these could not give me names like /system/bin/debuggerd, etc.

NOTE: I am running Android-4.2 Jellybean, on Non-Rooted device.

like image 325
AADProgramming Avatar asked Jan 11 '15 09:01

AADProgramming


People also ask

How do I find out what apps are running in the background on my Android?

Since battery life is so important, it's well monitored by your Android OS. To look at the background apps guzzling power, go to Settings > Battery > Battery Usage. You'll get a list of what's draining your battery, and by how much.

How do I see which apps are running?

In phones with Android 6 or later, go to the Developer options > Running services setting to see the running apps list.

How do I close all background processes in Android?

Tap and hold on the application and swipe it to the right. This should kill the process from running and free up some RAM. If you want to close everything, press the "Clear All" button if its available to you. 4. Navigate to the Apps tab in settings if your phone's still running slow.


1 Answers

By calling an API from ActivityManager, you're only getting the applications which registered with it - that is, UI activities - and not all the processes. Those you see with a non-reverse DNS name, but a path (e.g. /system/bin/*) are native daemons, started by init, and left out of the ActivityManager.

One way around this is to get the list of processes directly from /proc (just like toolbox's ps does it). This requires iterating programmatically over the directories there, (i.e. /proc/[0-9]*), and pruning out the kernel threads. Kernel threads are those with a PPID of 2, so they're easy. Native daemons will have a PPID of 1. Applications will have a PPID of Zygote.

Reference: NewAndroidBook.com

like image 161
Technologeeks Avatar answered Oct 16 '22 08:10

Technologeeks