This article will introduce how to get the processes and threads running on a device from adb, as well as to get information about memory usage.
You can use the following commands to get these information:
adb shell ps -ef
: prints the list of running processesadb shell ps -T
: prints the list of running threadsadb shell dumpsys meminfo [package name|pid]
: prints a snapshot of the memory usage of the running process
Let's take a look at each command with an example.
1. "ps" command from adb
The adb shell provides a ps
command like Linux. With the ps command, you can print out a list of processes and threads.
$ adb shell ps --help
usage: ps [-AadefLlnwZ] [-gG GROUP,] [-k FIELD,] [-o FIELD,] [-p PID,] [-t TTY,] [-uU USER,]
List processes.
Which processes to show (-gGuUpPt selections may be comma separated lists):
-A All -a Has terminal not session leader
-d All but session leaders -e Synonym for -A
-g In GROUPs -G In real GROUPs (before sgid)
-p PIDs (--pid) -P Parent PIDs (--ppid)
-s In session IDs -t Attached to selected TTYs
-T Show threads also -u Owned by selected USERs
-U Real USERs (before suid)
Output modifiers:
-k Sort FIELDs (-FIELD to reverse) -M Measure/pad future field widths
-n Show numeric USER and GROUP -w Wide output (don\'t truncate fields)
Which FIELDs to show. (-o HELP for list, default = -o PID,TTY,TIME,CMD)
-f Full listing (-o USER:12=UID,PID,PPID,C,STIME,TTY,TIME,ARGS=CMD)
-l Long listing (-o F,S,UID,PID,PPID,C,PRI,NI,ADDR,SZ,WCHAN,TTY,TIME,CMD)
-o Output FIELDs instead of defaults, each with optional :size and =title
-O Add FIELDS to defaults
-Z Include LABEL
2. Process list running on the device
The following command prints out all the process information currently running on the device.
$ adb shell ps -ef
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 07:14:10 ? 00:00:02 init second_stage
root 2 0 0 07:14:10 ? 00:00:00 [kthreadd]
root 4 2 0 07:14:10 ? 00:00:00 [kworker/0:0H]
root 5 2 0 07:14:10 ? 00:00:01 [kworker/u8:0]
root 6 2 0 07:14:10 ? 00:00:00 [mm_percpu_wq]
If you use the grep command together, then you can get only the information of the package or process that you want to search for.
$ adb shell ps -ef | grep system_server
system 2033 1777 5 07:14:18 ? 00:00:32 system_server
3. Thread list running on the device
The following command prints information about all threads currently running on the device.
$ adb shell ps -T
USER PID TID PPID VSZ RSS WCHAN ADDR S CMD
root 1 1 0 31784 5120 0 0 S init
root 2 2 0 0 0 0 0 S kthreadd
root 4 4 2 0 0 0 0 I kworker/0:0H
If you want to get only the threads running in a particular process, you can put the PID as an option.
In this example, pid 2033
is the pid of system_server
. and you can get thread list of system_server
$ adb shell ps -T 2033
USER PID TID PPID VSZ RSS WCHAN ADDR S CMD
system 2033 2033 1777 2111796 193180 0 0 S system_server
system 2033 2039 1777 2111796 193180 0 0 S Jit thread pool
system 2033 2040 1777 2111796 193180 0 0 S Runtime worker
system 2033 2041 1777 2111796 193180 0 0 S Runtime worker
....
3. How to get memory usage
The command dumpsys meminfo
will output a snapshot of the memory usage of the running processes.
$ adb shell dumpsys meminfo
Applications Memory Usage (in Kilobytes):
Uptime: 1474836 Realtime: 1474836
Total PSS by process:
80,647K: system (pid 2033)
80,004K: com.google.android.googlequicksearchbox:search (pid 2813)
78,513K: zygote (pid 1777)
70,264K: com.android.systemui (pid 2173)
58,396K: com.android.chrome (pid 5356)
55,579K: com.google.android.gms (pid 2756)
51,626K: com.google.android.gms.persistent (pid 2579)
47,787K: com.google.android.youtube (pid 3887)
44,664K: com.google.android.apps.nexuslauncher (pid 2439 / activities)
34,097K: com.google.android.apps.messaging (pid 3476)
31,900K: com.google.android.inputmethod.latin (pid 2485)
30,176K: com.google.android.apps.messaging:rcs (pid 5233)
....
3.1 Memory usage of a specific process
If you want to get only the memory information of a particular process, you can pass the pid or package name as an argument in the command.
- adb shell dumpsys meminfo [pid]
- adb shell dumpsys meminfo [package name]
In this example, this command show the memory usage of pid 2033 (system_server)
.
$ adb shell dumpsys meminfo 2033
Applications Memory Usage (in Kilobytes):
Uptime: 1080927 Realtime: 1080927
** MEMINFO in pid 2033 [system] **
Pss Private Private Swap Heap Heap Heap
Total Dirty Clean Dirty Size Alloc Free
------ ------ ------ ------ ------ ------ ------
Native Heap 21249 21184 0 0 27612 23433 4178
Dalvik Heap 17323 17272 0 0 17135 10991 6144
Dalvik Other 1976 1976 0 0
Stack 36 36 0 0
...
In this example, this command show the memory usage of the package com.google.android.youtube
.
$ adb shell dumpsys meminfo com.google.android.youtube
Applications Memory Usage (in Kilobytes):
Uptime: 3699899 Realtime: 3699899
** MEMINFO in pid 6789 [com.google.android.youtube] **
Pss Private Private Swap Heap Heap Heap
Total Dirty Clean Dirty Size Alloc Free
------ ------ ------ ------ ------ ------ ------
Native Heap 36159 36096 0 0 48536 46675 1860
Dalvik Heap 9405 9340 0 0 13414 7286 6128
Dalvik Other 6272 6272 0 0
Stack 56 56 0 0
If you would like to know in detail what the output means, please refer to Android developer.
Related Posts
- How to download and build Android 13, AOSP
- Notification permission request, pop up notification in Android 13
- Resolve `Access blocked: ComponentInfo` error on Android 13
- Fix error "android gradle plugin requires java 11 to run. you are currently using java 1.8."
- Android - Vibration, Vibrator, VibrationEffect example
- How to get phone number in Android
- How to create Bugreports and Logcat with ADB in Android
- Clear application user data with ADB in Android
- How to disable/enable apps with ADB in Android
- How to find PID of a package with adb in Android
- How to grant/revoke permissions with adb in Android
- How to install an apk(app) with adb in Android
- How to kill a process/package from ADB in Android
- How to transfer files using adb push/pull command in Android
- How to capture the screen from adb in Android
- How to uninstall/install system apps from adb in Android
- How to change Settings values from adb in Android
- How to Factory reset with ADB in Android
- How to get logcat from ADB command in Android
- How to capture Heap Dump from app with ADB in Android
- How to force stop an app with adb in Android
- How to start/stop a service from adb in Android
- How to send/broadcast an intent from adb command in Android
- How to start an activity from adb in Android
- How to generate input from adb in Android
- How to check SQLite DB table in Android Studio
- How to get memory info and thread list from adb in Android
- Android - Uri, Scheme and SSP(Scheme Specific Part)
- How to parse a xml file with XmlResourceParser in Android
- Android - Signing an apk with Platfom key
- How to fix "Cleartext HTTP ... not permitted" for Android development
- How to fix "kvm permission denied" for Android Emulator
- Using ADB over Wifi for Android development