How to get android background running process deta

2019-03-20 08:41发布

问题:

I want to list all background running processes and get details of those from one background service(Without UI). Details are as follows:

1. Name
2. Memory usage
3. Application related to process
4. Files they are accessing
5. Last modified time of files

I can get list of background running processes but how to get memory usage, Files they are accessing and Last modified time of files. Is this possible to implement at API level? Can anyone guide me How to do this? Can anybody give me idea or suggest useful link related to this.

回答1:

The Running Services UI uses getRunningAppProcesses, getProcessMemoryInfo, and getRunningServices.

Note that these only tell you about Java processes being managed by the high-level system; getRunningAppProcesses will not return information about low-level daemon processes.

The kernel has information about open files under /proc, but you can not get the information about another process unless you are running as root.

Also all currently running processes are under /proc, but please note that /proc is not a part of the Android SDK and there are no guarantees that your application will work across all devices or versions of the platform if using that. /proc is a private implementation detail.



回答2:

With following line of code you can get currently running services list

ActivityManager localActivityManager = (ActivityManager) getSystemService(Activity.ACTIVITY_SERVICE);

List RunningServiceInfoservices = localActivityManager.getRunningServices(100);

And from RunningServiceInfo you can get details for the process. http://developer.android.com/reference/android/app/ActivityManager.RunningServiceInfo.html