Running code when a script exits

A thing to realise here is that the handling of Ctrl-G and its commands only work when you are running a shell. Without a shell this interface is not generally not started. You can see this if you look in the elixir shell script and see that when an iex shell is not start then there is a -noshell argument to the resultant erl command. Doing elixir foo.exs does not start a shell and, hence, no handling of Ctrl-G and q.