Editing
OTP Supervisor
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!
== OTP Supervisor == [[File:Supervisor_Tree.png|thumb|right|250px|A supervisor supervising a supervision tree of processes.]] The OTP Supervisor is a vital component in the OTP (Open Telecom Platform) framework of the Elixir programming language. As the name suggests, it is responsible for supervising and managing the lifecycle of child processes. The OTP Supervisor provides fault tolerance and recovery capabilities by monitoring and restarting child processes when necessary. === Overview === The OTP Supervisor plays a crucial role in building robust and fault-tolerant applications using Elixir. It acts as a process supervisor that monitors and controls the execution of a group of related processes, known as a supervision tree. A supervision tree is a hierarchical structure in which processes are organized in a tree-like manner. Each process has one parent and can have multiple child processes. The OTP Supervisor is positioned at the top of the tree, acting as the root supervisor. It is responsible for managing the lifecycle of all the processes within its supervision tree. === Responsibilities === The OTP Supervisor has the following key responsibilities: * Starting child processes and ensuring their proper initialization. * Monitoring the health of child processes. * Restarting failed or terminated child processes. * Propagating exit signals to other supervised processes in the tree. * Managing the restart strategy and intensity of child processes. === Restart Strategies === When a child process fails, it is the responsibility of the OTP Supervisor to handle the failure and initiate the appropriate actions. The OTP Supervisor supports different restart strategies, each defining a specific approach to handle failures. Some commonly used restart strategies include: * OneForOne: Restarts only the failed child process, leaving other processes unaffected. * OneForAll: Restarts all child processes within the same supervision tree. * RestForOne: Restarts the failed process and all its sibling processes. === Example Usage === Below is an example code snippet demonstrating the usage of the OTP Supervisor: ```elixir defmodule MyApp.Supervisor do use Supervisor def start_link(arg) do Supervisor.start_link(__MODULE__, arg, name: __MODULE__) end def init(arg) do children = [ worker(MyApp.Worker, [arg]) ] supervise(children, strategy: :one_for_one) end end ``` In this example, `MyApp.Supervisor` defines a supervision behavior using the `Supervisor` module. It starts a single child process (`MyApp.Worker`) and specifies the restart strategy as `:one_for_one`. === See Also === * [[OTP]] * [[Supervisor]] * [[Supervision Tree]] * [[Fault Tolerance]] {{Elixir}} [[Category:OTP]] [[Category:Supervision]] [[Category:Fault Tolerance]] [[Category:Elixir]]
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:Elixir
(
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