Hermanverschooten

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

DidactMacros

If Elixir ever gets a magazine it should be called ctrl-GQ.

I’ll see myself out.

acangiano

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

gregvaughn

I learned ctrl-g q from an Erlanger early in my Elixir career and taught it to my fingers.

03juan

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… :lol:

iex> System.restart()

It’ll recompile and reload everything for you.

acangiano

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.

Where Next?

Popular in Questions Top

fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
vac
Hi, I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
Phillipp
Hey, I have a NanoPi-M3 and try to install Elixir on their Ubuntu image. I followed the Raspberry Pi installation instructions from the ...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
chewm
Hi guys, nice to meet you to the whole forum, I’m new here, I’m trying to configure visual studio code for elixir, right now the intellis...
New
hpopp
To simplify some tasks at work, I wrote and published this package yesterday. It’s a simple macro that enables Access behaviour on struct...
New
wernerlaude
In AR this is so simple @articles = current_user.articles How to do in Ecto? def index(conn, _params) do current_user = conn.assig...
New
jc00ke
Expanding on this topic: https://forum.elixirforum.net/t/map-typespec-question/19217 Let’s say I have a map with required and optional k...
New

Other popular topics Top

itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: https://hexdocs.pm/ecto/Ecto.Schema.html#module-...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 49522 488
New
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
mgjohns61585
Could someone help me? I'm making my first elixir program, number guessing game. I can't figure out how to convert the user's guess from ...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New

We're in Beta

About us Mission Statement