The Good

There are several ways to shutdown an Erlang VM nicely…

1. q/0, c:q/0, init:stop/0

The simplest and cleanest one is to just use q/0 or c:q/0 (which are, actually, the same thing), as the docs puts it…

This function is shorthand for init:stop() , that is, it causes the node to stop in a controlled fashion.

And init:stop/0 is…

The same as stop(0) .

So, basically you end up running init:stop(0). To understand what that command does, let’s check the docs again:

All applications are taken down smoothly, all code is unloaded, and all ports are closed before the system terminates by calling halt(Status) . If command-line flag -heart was specified, the heart program is terminated before the Erlang node terminates. For more information, see heart(3) . To limit the shutdown time, the time init is allowed to spend taking down applications, command-line flag -shutdown_time is to be used.

So, the cleanest shutdown possible. But you can also skip all the clean part and jump straight to…

2. erlang:halt/0

As you can see in the docs, erlang:halt() is the same as erlang:halt(0, []). More on erlang:halt/1,2 below, but for now erlang:halt() just runs a shutdown of the VM where no application is properly terminated and no port is properly closed.

3. JCL mode

The previous methods rely on you being able to run commands in the shell (or remotely, if you’re using distributed Erlang). What if you can’t do that because, for instance, you blocked your shell or something? Well if you’re in the shell of the node you want to turn down, even if it’s not receiving input, you can still press Ctrl-g (which takes you to JCL mode). Once there you can use the command q to quit the Erlang shell.

This is similar in effect to erlang:halt(0).

This is, by the way, the best way to stop a remsh node without stopping the original node.

4. BREAK mode

Instead of Ctrl-g, you can press Ctrl-c. That takes you to BREAK mode, which looks like this:

BREAK: (a)bort (c)ontinue (p)roc info (i)nfo (l)oaded

(v)ersion (k)ill (D)b-tables (d)istribution

You can do two things to shut down the node there:

Press Ctrl-c again.

again. Press a and then return.