Skip to content

Instantly share code, notes, and snippets.

@royclarkson
Created May 1, 2014 16:14
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save royclarkson/f39115fe0a7ac1f08630 to your computer and use it in GitHub Desktop.
Save royclarkson/f39115fe0a7ac1f08630 to your computer and use it in GitHub Desktop.
Bash script to kill all running Android emulators
#!/bin/bash
for ((PORT=5554; PORT<=5584; PORT+=2)); do
echo killing emulator-$PORT...
adb -s emulator-$PORT emu kill
done
@kenkyee
Copy link

kenkyee commented May 13, 2015

Should append " || true" to the kill command so it doesn't return errors for non-running emulators...

@igorwojda
Copy link

Nowadays we can retrieve a list of all emulators with corresponding ports and kill emulators that actually exists

adb devices | grep "emulator-" | while read -r line ; do
    suffix="	device"
    emulatorInstanceName=${line%${suffix}}

    echo "Killing $emulatorInstanceName"
    adb -s ${emulatorInstanceName} emu kill
done

@bval
Copy link

bval commented Mar 22, 2019

This gist was super helpful to me in some CI scripting. Wanted to point out for future spelunkers that the loop above can use the ability of read to assign multiple variables to eliminate the munging of emulatorInstanceName like so:

adb devices | grep "emulator-" | while read -r emulator device; do
  adb -s $emulator emu kill
done

@bwoodlt
Copy link

bwoodlt commented Aug 12, 2022

Another take:

#!/bin/bash
devices=`adb devices`

for device in $devices; do
    if [[ "$device" =~ "emulator-" ]]; then
      adb -s $device emu kill
      echo $device removed
    fi    
done    
echo "All Done."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment