How to shut down Android emulator via command line How to shut down Android emulator via command line android android

How to shut down Android emulator via command line


Please don't use kill -9 indiscriminately, it's a very bad habit.

The correct command is

 $ adb emu kill

Or I should better say it was the correct command until some recent adb changes. It seems somebody forgot to add the authentication to it.

In the latest (as of June 2016) the latest adb version is

$ adb versionAndroid Debug Bridge version 1.0.36Revision 0a04cdc4a62f-android

and when you try

$ adb emu kill

nothing happens, and this is why

...connect(3, {sa_family=AF_INET, sin_port=htons(5554), sin_addr=inet_addr("127.0.0.1")}, 16) = 0write(3, "kill\nquit\n", 10)            = 10read(3, "\377\373\1", 8192)             = 3read(3, "\377\373\3\377\373\0\377\375\0", 8192) = 9read(3, "Android Console: Authentication required\r\nAndroid Console: type 'auth <auth_token>' to authenticate\r\nAndroid Console: you can find your <auth_token> in \r\n'/home/diego/.emulator_console_auth_token'\r\nOK\r\n", 8192) = 202read(3, "k\33[K", 8192)                 = 4read(3, "\33[Dki\33[K", 8192)           = 8read(3, "\33[D\33[Dkil\33[K\33[D\33[D\33[Dkill\33[K", 8192) = 28read(3, "\r\nKO: unknown command, try 'help'\r\n", 8192) = 35read(3, "q\33[K\33[Dqu\33[K", 8192)     = 12read(3, "\33[D\33[Dqui\33[K\33[D\33[D\33[Dquit\33[K", 8192) = 28read(3, "\r\n", 8192)                   = 2read(3, "", 8192)                       = 0close(3)                                = 0exit_group(0)                           = ?+++ exited with 0 +++

Then we need another solution.

If the previous command does not work (as some users reported for Windows) you can try (in the next command 5554 is the port used by the emulator).

Copy the content of the token file (~/.emulator_console_auth_token) to the clipboard so you can paste it during your telnet session:

$ telnet localhost 5554Trying 127.0.0.1...Connected to localhost.Escape character is '^]'.Android Console: Authentication requiredAndroid Console: type 'auth <auth_token>' to authenticateAndroid Console: you can find your <auth_token> in '/home/user/.emulator_console_auth_token'OKauth <YOUR_TOKEN_HERE>Android Console: type 'help' for a list of commandsOKAndroid console command help:    help|h|?         print a list of commands    crash            crash the emulator instance    kill             kill the emulator instance    quit|exit        quit control session    redir            manage port redirections    power            power related commands    event            simulate hardware events    avd              control virtual device execution    finger           manage emulator fingerprint    geo              Geo-location commands    sms              SMS related commands    cdma             CDMA related commands    gsm              GSM related commands    rotate           rotate the screen by 90 degreestry 'help <command>' for command-specific helpOK

Then, you can just enter kill at the command prompt

killOK: killing emulator, bye byeConnection closed by foreign host.

and the emulator will exit.

But wait, there should be a better way. And in fact there is!

This gist provides an automated solution using expect instead of having to cut and past the authentication token every time.

Hope you find it useful.


I had issues in ubuntu where the emulator would continuously open new processes. I could never close the emulator and it was unresponsive.

I used htop

Steps in htop:

  1. F4 to filter.
  2. Filter for 'avd'.
  3. F5 for tree.
  4. Find and click on parent process.
  5. F9 to raise kill menu.
  6. Select signal 9 and enter.


On Ubuntu 16-04, using ADB version 1.0.32, I'm running the emulator for Android 4.4 (API 19) in a docker container. The exposed ports are 30004 for the console and 30005 for ADB.

I can connect to it by doing adb connect 0.0.0.0:30005.

To kill the emulator though, I have to use adb -s emulator-30004 emu kill, using 0.0.0.0:30005 gives me error: no emulator detected.