Editing
Supervisors
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!
== Supervisors == A supervisor is a behavior in Elixir that helps in building fault-tolerant systems. It is responsible for starting, monitoring, and restarting child processes, ensuring the stability and resiliency of the system. === Role of Supervisors === Supervisors use a "let-it-crash" philosophy to handle faults. When a child process crashes, the supervisor is notified, and depending on the restart strategy, it can decide how to handle the failure. In Elixir, supervisors are implemented using the `Supervisor` module. They are defined as part of a supervision tree, which is a hierarchical structure that organizes the processes of an application. Each supervisor can have multiple child processes. === Starting Child Processes === Supervisors start child processes using the `start_child` function, specifying the child specification. A child specification describes how a child process is started and how it should be supervised. === Restart Strategies === Elixir provides different restart strategies that supervisors can use when a child process crashes: - `:one_for_one`: This strategy restarts only the failed child process. - `:one_for_all`: This strategy restarts all child processes. - `:rest_for_one`: This strategy restarts the failed child process and all the ones that were started after it. === Handling Faults === When a child process crashes, the supervisor is notified and can take further action. Supervisors can choose if they want to restart the failed child process immediately or have a delay before attempting a restart. Supervisors can also define a maximum number of restart attempts within a given time period. If a child process fails too many times within this limit, the supervisor can take other actions, like shutting down the entire application. === Linking to Other Articles === Visit the following articles to learn more about supervisors and related topics: - [[Processes]]: Explains the basics of processes in Elixir. - [[OTP Behaviors]]: Discusses different OTP behaviors, including supervisors. - [[Supervisor Strategies]]: Provides in-depth explanations of the available restart strategies. - [[Supervision Trees]]: Details how supervision trees are structured and how supervisors are organized within them. By employing supervisors in your Elixir applications, you can enhance fault tolerance and build robust systems. {{Programming languages}}
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:Programming languages
(
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