Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get info about all running processes [closed]

I have an idea to make Task Manager for android.Can anyone tell me how to get all the processes currently running in android?

like image 400
Zaid Iqbal Avatar asked Sep 08 '14 10:09

Zaid Iqbal


People also ask

How can I tell what processes are running and stopped?

You can list running processes using the ps command (ps means process status). The ps command displays your currently running processes in real-time. This will display the process for the current shell with four columns: PID returns the unique process ID.

How do I get a list of running processes?

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.

How do I find PID of all processes?

Task Manager can be opened in a number of ways, but the simplest is to select Ctrl+Alt+Delete, and then select Task Manager. In Windows, first click More details to expand the information displayed. From the Processes tab, select Details to see the process ID listed in the PID column. Click on any column name to sort.

How do I see all processes that have been stopped in Linux?

ps -e lists all processes. jobs list all processes currently stopped or in background. Job control and their commands are specific to the shell, there is no general jobs command, it's a shell built-in command.


1 Answers

using the code below you can get the list of running processes:-

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

for(RunningAppProcessInfo runningProInfo:procInfos){

        Log.d("Running Processes", "()()"+runningProInfo.processName);
}

For more information you can visit this link.

To get the application name based on package name use PackageManager class.

final PackageManager pkgmgr = getApplicationContext().getPackageManager();
ApplicationInfo appinfo;
try {
    appinfo = pkgmgr.getApplicationInfo( this.getPackageName(), 0);
} catch (final NameNotFoundException e) {
    appinfo = null;
}
final String applicationName = (String) (appinfo != null ? pkgmgr.getApplicationLabel(appinfo) : "(unknown)");

To get the app name on the basis of PID use:-

public static String getAppNameByPID(Context context, int pid){
    ActivityManager manager 
               = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);

    for(RunningAppProcessInfo processInfo : manager.getRunningAppProcesses()){
        if(processInfo.pid == pid){
            return processInfo.processName;
        }
    }
    return "";
}

and finally to check if an app is system app or not use:-

private boolean isSystemPackage(PackageInfo pkgInfo) {
        return (pkgInfo.applicationInfo.flags & 
                ApplicationInfo.FLAG_SYSTEM) != 0;
    }
like image 164
Amit Anand Avatar answered Sep 21 '22 00:09

Amit Anand