# Elixir Multiple Processes

**URL:** <https://forum.elixirforum.com/t/elixir-multiple-processes/21146>\
**Category:** Questions\
**Tags:** agent, processes, genserver\
**Created:** [March 26, 2019, 10:24am UTC](https://forum.elixirforum.com/t/elixir-multiple-processes/21146 "2019-03-26T10:24:56Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![kokolegorille](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/kokolegorille/32/4784_2.png) [@kokolegorille](https://forum.elixirforum.com/u/kokolegorille)\
**Post date:** [March 26, 2019, 6:22pm UTC](https://forum.elixirforum.com/t/elixir-multiple-processes/21146/4 "2019-03-26T18:22:34Z")

</div>

The shell is already a process. The magic words are **spawn** , and **send**. You might also want to learn about Link and Monitor, which are the basic blocks, on which OTP is built upon.

```elixir
$ iex
Erlang/OTP 21 [erts-10.2.3] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [hipe]

Interactive Elixir (1.8.1) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> self()
#PID<0.107.0>
iex(2)> calculate = fn a, b, _action -> IO.puts(a + b) end
#Function<18.128620087/3 in :erl_eval.expr/5>
iex(3)> spawn fn -> calculate.(1, 2, :add) end
3
#PID<0.111.0>

```

This example just print some output, but You can pass self() as a parameter to the message, and have the spawned process send back the result to the calling process.

```elixir
iex(1)> pid = self()  
#PID<0.107.0>
iex(2)> calculate = fn a, b, pid -> send(pid, {:result, a + b}) end
#Function<18.128620087/3 in :erl_eval.expr/5>
iex(3)> spawn fn -> calculate.(1, 2, pid) end
#PID<0.111.0>
iex(4)> flush
{:result, 3}
:ok

```

You might like

> **[Erlang master classses - School of Computing - University of Kent](https://www.cs.kent.ac.uk/ErlangMasterClasses/)**

in particular Master class 2, which is about turning sequential programming into concurrent.

---

_[View the full topic](https://forum.elixirforum.com/t/elixir-multiple-processes/21146)._
