__ __
___ _ __ \ \/ / ___ ___
/ _ \| '__| \ / / _ \ / __|
| __/| | / \ | (_) |\__ \
\___||_| /_/\_\ \___/ |___/
erXos
development build: trusted code only
Erlang/OTP 29 [erts-17.1.1] [source] [64-bit] [smp:1:1] [ds:1:1:10] [async-threads:1]
rc: the command shell; erl starts the Erlang shell
% # The command shell runs rc's language, written in Erlang.
% ls /
NOTICES
bin
lib
manifest
root
% echo hello from erXos > /tmp/hi
% cat /tmp/hi
hello from erXos
% # How many processes run? Each is an Erlang process.
% ps | wc -l
62
% erl
Eshell V17.1.1 (type help(). for help)
% Crash a process that divides by zero, and catch it
% with a monitor. The shell carries on.
1> {_, R} = spawn_monitor(fun() -> 1 / list_to_integer("0") end).
=ERROR REPORT==== 1-Jan-1970::00:00:02.651025 ===
Error in process <0.150.0> with exit value:
{badarith,[{erlang,'/',[1,0],[{error_info,#{module => erl_erts_errors}}]}]}
{<0.150.0>,#Ref<0.3910384898.1.60465>}
2> receive {'DOWN', R, _, _, {E, _}} -> {crashed, E} end.
{crashed,badarith}
% A ring of N processes passes a token round it Laps times.
3> Ring = fun(N, Laps) ->
.. Last = lists:foldl(fun(_, Next) ->
.. spawn(fun Loop() -> receive 0 -> Next ! 0;
.. T -> Next ! T - 1, Loop() end end)
.. end, self(), lists:seq(1, N)),
.. Alive = erlang:system_info(process_count),
.. Last ! N * Laps,
.. (fun Wait() -> receive 0 -> ok;
.. T -> Last ! T - 1, Wait() end end)(),
.. {Alive, N * Laps}
.. end.
#Fun<erl_eval.41.130099583>
% 5,000 processes alive at once, 100,000 messages.
4> Ring(5000, 20).
{5061,100000}