Editing
Quixir/Processes
(section)
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Quixir/Processes == [[File:Elixir_Logo.png|thumb|left|Elixir Logo]] Processes play a vital role in the Quixir programming language. In Quixir, processes are lightweight and isolated units of execution. They provide concurrency, fault tolerance, and distribution capabilities to build highly scalable and fault-tolerant systems. === Introduction === A process in Quixir is a unit of computation that runs concurrently with other processes. Each process has its own independent memory space, known as a heap, where it stores its variables and data. Processes communicate with each other by sending and receiving messages, allowing for easy coordination and cooperation. === Creating Processes === In Quixir, processes are created using the `spawn/1` or `spawn/3` functions. The `spawn/1` function takes a function as an argument and spawns a new process to execute that function. The `spawn/3` function is similar but also allows specifying the module and function name to be executed. Example: ```elixir pid = spawn(fn -> IO.puts "Hello from a new process!" end) ``` === Sending and Receiving Messages === Processes communicate by sending and receiving messages using the `send/2` and `receive/1` functions. The `send/2` function sends a message to a specified process, identified by its process identifier (PID). Example: ```elixir pid = spawn(fn -> receive do message -> IO.puts "Received: #{inspect message}" end end) send(pid, "Hello!") ``` === Process Linking === In Quixir, processes can be linked together to establish fault-tolerant systems. Linking two processes results in a bi-directional connection where a failure in one process will cause an exit signal to be sent to the linked process. Example: ```elixir pid = spawn(fn -> receive do {:shutdown, reason} -> IO.puts "Received shutdown signal: #{reason}" Process.exit(self(), :shutdown) end end) Process.link(pid) ``` === Supervision === Supervision is a mechanism in Quixir for building fault-tolerant systems. Instead of focusing on handling individual failures, supervision strategies allow for the monitorization and supervision of a group of related processes. === References === * [https://elixir-lang.org/docs.html Elixir Documentation] * [https://hexdocs.pm/elixir/ Process Module Documentation] {{Elixir}} [[Category:Elixir (programming language)]] [[Category:Concurrency]] [[Category:Distributed computing]]
Summary:
Please note that all contributions to Elixir Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Elixir Wiki:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Create account
Log in
Namespaces
Page
Discussion
English
Views
Read
Edit
View history
More
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Tools
What links here
Related changes
Special pages
Page information