Editing
Erlang Processes
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!
== Erlang Processes == [[File:Elixir Erlenmeyer flask.png|thumb|right|Elixir language logo, inspired by the Erlenmeyer flask.]] Erlang processes are a fundamental building block in the Elixir programming language, providing lightweight concurrent programming capabilities. They are not operating system processes but rather lightweight entities managed by the Erlang virtual machine (BEAM). == Overview == Erlang processes in Elixir provide a concurrent and fault-tolerant mechanism for executing code independently. Each process has its own mailbox to receive messages and can spawn new processes, creating a tree-like structure known as the process tree. == Key Features == The key features of Erlang processes in Elixir include: === Concurrency === Erlang processes allow for the execution of multiple code paths simultaneously, reducing the need for complex synchronization mechanisms. === Fault-tolerance === When a process crashes due to an exception, it can be easily restarted or terminated without affecting other processes in the system. === Message Passing === Processes communicate with each other by sending and receiving messages asynchronously. Messages are received in the order they were sent and are stored in the receiving process's mailbox until processed. === Process Linking === Processes can be linked together, creating a relationship where if one process terminates abnormally, the other linked processes are also terminated. === Process Monitoring === In addition to process linking, Elixir provides process monitoring capabilities, enabling processes to monitor the status of other processes and take appropriate actions in case of failure. == Spawn and Creating Processes == In Elixir, new processes are spawned using the `spawn/1` or `spawn/3` functions. The `spawn/1` function takes a function as an argument and creates a new process that executes the provided function. Example: ```elixir spawn(fn -> IO.puts "Hello, world!" end) ``` == Sending and Receiving Messages == Elixir provides the `send/2` function to send messages to other processes. The messages are then stored in the receiving process's mailbox until processed using the `receive/1` or `receive/2` functions. Example: ```elixir send(pid, :message) ``` ```elixir receive do message -> IO.puts "Received: #{message}" end ``` == Process Monitoring == Elixir allows processes to monitor the status of other processes using the `Process.monitor/1` function. The monitoring process will receive an asynchronous message when the monitored process terminates. Example: ```elixir pid = spawn(fn -> raise "Oops!" end) ref = Process.monitor(pid) receive do {:DOWN, ^ref, :process, ^pid, _reason} -> IO.puts "Process terminated" end ``` == Conclusion == Erlang processes are a powerful feature of the Elixir programming language, offering lightweight concurrency, fault-tolerance, and message passing capabilities. Understanding how to create, monitor, and communicate between processes is crucial for building robust and concurrent Elixir applications. == See Also == * [[Concurrency in Elixir]] * [[Fault-Tolerance in Elixir]] * [[Message Passing in Elixir]] * [[Process Monitoring in Elixir]] == References == {{reflist}} [[Category:Elixir Programming Language]] [[Category:Concurrency]] [[Category:Fault-Tolerance]] [[Category:Message Passing]] [[Category:Process Monitoring]]
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)
Template used on this page:
Template:Reflist
(
edit
)
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