Android中进程相关信息获取,pid,进程名

1. 获取pid

int pid = android.os.Process.myPid();

2. 获取进程名及其他信息

ActivityManager mActivityManager = (ActivityManager) getContext().getSystemService(Context.ACTIVITY_SERVICE);
for (ActivityManager.RunningAppProcessInfo appProcess : mActivityManager
        .getRunningAppProcesses()) {
    if (appProcess.pid == pid) {
        procName = appProcess.processName;
    }
}

appProcess中可以获取一些进程相关的信息,如:

        /**
         * The name of the process that this object is associated with
         */
        public String processName;

        /**
         * The pid of this process; 0 if none
         */
        public int pid;

        /**
         * The user id of this process.
         */
        public int uid;

        /**
         * All packages that have been loaded into the process.
    

文章来源于互联网:Android中进程相关信息获取,pid,进程名