简体   繁体   中英

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.在我的设备中运行进程

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.

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 (eg /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, (ie /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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM