Erlang / Erlang Basics Interview questions
What is the difference between spawn and spawn_link?
Both start a new process and return its PID, but they differ in what happens when that new process terminates abnormally.
| spawn | spawn_link |
| Caller and new process are independent; if the child crashes, the caller is unaffected. | Caller and new process are linked; if either crashes, the other receives an exit signal too. |
| You must set up monitoring manually to be notified of a crash. | By default, an abnormal exit propagates and kills the linked process unless it's trapping exits. |
Because a crash silently propagating can be exactly what you want (fail the whole group together) or exactly
what you don't (an isolated worker), OTP supervisors use spawn_link internally combined with
process_flag(trap_exit, true), so the supervisor is notified of the crash instead of being killed
by it.
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
