Skip to content

Embed URL


Subversion checkout URL

You can clone with
Download ZIP
Demo session used for "Introduction to Erlang" talks and courses.

Start an instance of the Erlang run-time system

$ erl

Show information about processes

> i().

Spawn a new process which sleeps for 10 seconds

> spawn(timer, sleep, [10000]).

Verify that the process is listed among the other processes

> i().

Get the PID of the current process

> self().

Send a message to the current process

> self() ! ping.

Flush the mailbox of the current process

> flush().

Start a "named" instance of the Erlang run-time system (i.e. an Erlang node)

$ erl -sname italy

Start another one (in a separate terminal window)

$ erl -sname sweden

Retrieve the current node name

italy@pigeon> node().

Retrieve the current node name

sweden@pigeon> node().

Register the current process under the name foo

sweden@pigeon> register(foo, self()).

Send a message to the registered process

sweden@pigeon> foo ! local.

Send a message to a remote process (pigeon is the name of my machine)

italy@pigeon> {foo, 'sweden@pigeon'} ! {remote, self()}.

Flush the mailbox

sweden@pigeon> flush().

Assign the PID of the current process to the variable S

italy@pigeon> S = self().

Define an anonymous function which displays wow on the node where it gets executed and send a message to a process (which could be remote). The message contain the name of the node where the function is run.

italy@pigeon> F = fun() -> erlang:display(wow), S ! node() end.

Spawn a remote process which will execute the anonymous function

italy@pigeon> spawn('sweden@pigeon', F).

Verify that the message sent above has been received by the remote process

italy@pigeon> flush().
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.