Skip to content
Home » Android » How to Use ADB to Check Apps Running in Background

How to Use ADB to Check Apps Running in Background

Apps are crucial and indispensable to the Android experience. Some apps run in the foreground and are noticeable to the user, while others run stealthily in the background. Background apps and processes are essential to the proper functioning of an Android device. This tutorial will explore all working ADB commands that let you check apps running in the background and foreground on Android devices. Once you have the list of running apps and processes, their PID, and CPU and memory usage, you can identify the ones that need to be stopped.

ADB is a CLI tool that can perform tasks on a connected Android device or emulator from a Windows, macOS, or Linux computer. Among the things ADB can do on Android include finding out the running apps and processes. To explore the power of ADB, don’t forget to check out our exhaustive list of commands.

Before you can execute commands, you must first set up ADB on your computer and enable USB debugging on your Android.

List All Running Processes and Apps

There is a simple yet powerful ADB command to list all running processes in the background on a connected Android device. (PID means Process ID)

adb shell ps
or
adb shell ps -A

adb command to list all running processes on android

You can also use the following command to list all running activities on your Android device.

Check CPU and Memory Usage for Apps and Processes

The top command is used in Linux to get a real-time view of the running system processes. Being based on Linux, Android supports this command too.

Open the ‘platform-tools‘ folder that contains the ADB and Fastboot drivers. Type “powershell” in the folder’s address bar and hit Enter to launch a command window with its path.

launch powershell with the path of platform-tools

Extend your phone’s screen timeout to 5-10 minutes temporarily and connect it to your computer using a USB cable. Now execute the following command.

adb shell

After the $ sign type ‘top‘ and press Enter.

adb shell top command to check cpu usage for background processes

You can also use the above command as mentioned below.

adb shell top

It’s also possible to list the 5, 10, or any number of most CPU-hogging processes on your Android device.

adb shell top -m 10

If you want to sort top running processes by their memory and CPU consumption, use the following commands.

Sort by Memory usage: adb shell top -s 6

Sort by CPU usage: adb shell top -s 9

Like other ADB commands, this command can be used with certain variables to get more specific information.

  • -h: Usage graphs instead of text
  • -k: Fallback sort FIELDS (default -S,-%CPU,-ETIME,-PID)
  • -o: Show FIELDS (def PID, USER, PR, NI, VIRT, RES, SHR, S,%CPU, %MEM, TIME+, CMDLINE)
  • -s: Sort by field number (1-X, default 9)
  • -b: Batch mode (no tty)
  • -d: Delay SECONDS between each cycle (default 3)
  • -m: Maximum number of tasks to show
  • -n: Exit after NUMBER iterations
  • -p: Show these PIDs
  • -u: Show these USERs
  • -q: Quiet (no header lines)
Example: adb shell top -n 1

Get Top Activity on Android and Kill It

ADB can also list the top foreground activity with its PID and kill the running process.

Execute the following command in the command window.

adb shell "dumpsys activity | grep top-activity"

This will give you the top active process with its app package name and PID. You can use its PID to kill the process.

adb command to get top activity and kill the process

"kill <PID>"

Alternatively, you can use the following ADB command to kill a process by its PID.

adb shell kill <PID>

To find the PID of a specific app by its package name, try the following.

adb shell pidof <package-name>

find process id of an app using package name using adb

You can also check the currently running app with the command below.

adb shell dumpsys activity | awk -F '[ /}]' '/mCurrentFocus/{print $9}'

view currently active apps using adb command

Get the List of the Most Recently Used Apps

You can easily check recently opened apps by tapping the App Switcher icon on the navigation bar. Alternatively, you can list the recent apps and their current activity with minute details using the following ADB commands.

adb shell dumpsys activity recents

view recently used apps and processes adb

The following command will give you a more compact output.

adb shell dumpsys activity top | grep "ACTIVITY"

To get the currently active foreground app or activity, you can use the above command as shown below.

adb shell dumpsys activity top | grep "ACTIVITY" | tail -n 1

adb command to view recent apps on android

Check If an App is Running in the Background and Stop It

ADB also has a command to find a running app or process and kill it via ADB to save battery on Android.

  1. Open a command prompt window on your computer and connect your device using a USB cable.
  2. Execute the following command to enter the Shell.
    adb shell
  3. Now, type the command below to check if a specific app is running in the background.
    ps -A | grep <package-name>
  4. If the app is active in the background, ADB will show the user ID, PID, and memory usage.
  5. You can kill or stop the app using the following commands.
    • am kill <package-name>
    • am force-stop <package-name>
  6. To verify if the background app was killed or stopped successfully, rerun the following command.
    ps -A | grep <package-name>
  7. This time, you should get a blank output.checking if an app is running in the background and killing it with adb
  8. That’s it.

There is another command that kills apps safely as the Android OS does when it needs resources. However, since it uses xargs, it may not work on Windows

adb shell "ps | grep <package-name> | awk '{print $2}'" | xargs adb shell "run-as <package-name> kill"

Open Recents and Close Apps via ADB

When you use apps on your Android device, they are added to the Recents so you can switch between them quickly. Some of these apps may keep running in the background. You can view the recently used apps on Android by tapping the App Switcher button on the navigation bar and close them by selecting the Close all or Clear all option.

Alternatively, you can simulate the same action directly from your computer through ADB commands.

  1. Connect your Android device to your computer, launch a command window, and issue the following command to open Recents.
    adb shell input keyevent KEYCODE_APP_SWITCH
  2. When the Recents screen is open on your device, execute the following command twice one by one. Doing so will highlight the app in focus and then the Close all button.
    adb shell input keyevent KEYCODE_DPAD_DOWN
    adb shell input keyevent KEYCODE_DPAD_DOWN
    
  3. Finally, enter the following command to select the highlighted item.
    adb shell input keyevent KEYCODE_ENTER

    open recents app and close apps using adb commands

  4. This will close or clear all apps from the Recents screen.

Check Background Apps via ADB

You’ll be surprised to see the sheer number of background activities and processes running on an Android phone or tablet. To save yourself from getting overwhelmed, try the following command to list the apps running in the background on your Android device.

adb shell dumpsys activity activities
adb shell dumpsys activity services

To fetch the list of current activities, try this:

adb shell dumpsys activity activities | grep mActivityComponent | cut -d= -f2 | sort -u -m

get the list of apps running in background using adb command

Check Memory Usage for Apps and Device

ADB can also help you get a detailed overview of free and engaged memory on your device. Just execute the following command while your device is connected to the computer to check how much memory your apps are hogging. Using the battery parameter with the dumpsys command, you can check the battery’s health, capacity, and charge cycle count.

adb shell dumpsys meminfo

check memory usage for android apps via adb command

If you want to check the memory status only try the following.

adb shell "cat /proc/meminfo"

I have tested the ADB commands to check the foreground and background apps and processes on the Samsung Galaxy S24 Ultra with One UI 6.1. Try them to see if they work on your device.

Rakesh Shukla

Rakesh Shukla

Rakesh is a geek by heart with an ardent passion for all things tech. From a young age, he was drawn to the world of technology and found himself constantly tinkering with gadgets and devices. He enjoys learning and discovering the newest trends in the world of Android, iOS, and Windows.View Author posts