Hermanverschooten
Quitting an iex session - any difference between System.halt/1 & CTRL-C?
Generally when I want to quit an iex session I use the double control-c dance.
For unknown reasons this refused to work earlier today but I am not getting into that.
Because of it though I tried System.halt/1 to exit the session and that worked.
Is there a difference between the 2 methods?
Else I could add something like this to my .iex.exs
defmodule IexExtra do
def exit, do: System.halt()
end
import IexExtra
Then I can end my sessions with a plain and simple exit
Most Liked
DidactMacros
If Elixir ever gets a magazine it should be called ctrl-GQ.
I’ll see myself out.
acangiano
There are scenarios where CTRL-C twice could take down daemons running on a remote node. Not much harm if you are just messing around locally. However, if we are talking best practices, you’d probably want CTRL-G to bring up the User switch command menu, followed by q. Try h to see the options available.
gregvaughn
I learned ctrl-g q from an Erlanger early in my Elixir career and taught it to my fingers.
03juan
Here’s another tip courtesy of the System module.
You know “that” error…?
** (RuntimeError) could not compile application: my_app.
You must restart your server after changing the following files:
config/dev.exs
(phoenix 1.7.12) lib/phoenix/code_reloader/server.ex:236: Phoenix.CodeReloader.Server.mix_compile_unless_stale_config/4
Just do as it says… ![]()
iex> System.restart()
It’ll recompile and reload everything for you.
acangiano
The first CTRL-C gets you into the break menu which gives you a few diagnostic options. When you then press q or a and ENTER, or simply another CTRL-C you are effectively doing a System.halt(0) call.
CTRL-\ bypasses the break menu altogether and quits.
System.stop(0) is more graceful than System.halt(0). System.stop(0) signals :sigstop to the Erlang VM. It’s the same as calling :init.stop(0). From the documentation:
All applications are taken down smoothly, all code is unloaded, and all ports are closed before the system terminates by calling
halt(Status).
System.halt(0) signals a :sigquit to the VM, which is equal to calling :erlang.halt(0). It abruptly shuts down everything (no apps are gracefully stopped or ports properly closed.)
You’ll notice that System.stop(0) takes a moment to shut down and returns an :ok atom if successful. System.halt(0) is essentially immediate.







