paulanthonywilson
Elixir Blog Post: The many and varied ways to kill an OTP Process
This is an overview of different ways to try and kill an OTP process (in Elixir) and the behaviour to expect when that happens. I know this is fairly basic stuff, but it’s the kind of thing I find myself forgetting and having to recheck, and the documentation I know about is a bit scattered.
I hope to follow up with the impact on on linked and monitoring processes.
As a bonus, the post is an executable LiveBook page, which you can download and execute yourself.
Most Liked
ityonemo
this is where the special “exit from parent” is implemented: otp/lib/stdlib/src/gen_server.erl at master · erlang/otp · GitHub
the_wildgoose
This is excellent. Thankyou so much for writing this!
Just one point: I think there is a further difference in behaviour if the process doing the killing is the direct parent of the child? I’m actually not sure I understand the specifics, but there was a post on elixirforum a month or so back about this and the insight was that the child can’t catch it’s own exit if the thing sending the message is the direct parent? I think if this is correct then it would be quite nice to get this documented in your rather comprehensive write-up on this stuff!
I confess I still have a lot of doubts over how to correctly use OTP and especially how best to link some children and guarantee cleanup. I quite like the “parent” library for some of these things (“director” seems nice as well). I think it’s clear from your document that there are a few preferred ways to kill processes if you want to allow them to call their terminate() function. It does leave me with some doubts on how to handle this as a library author as well…
Looking forward to see if you do a followup on this on? Perhaps with regards to how to build robust links, cleanup on failure, monitor callers to ensure we terminate when our invoker terminates, etc?
Sebb
I think so too. Links are bidirectional, see Process — Elixir v1.12.3
But you can implement some stuff that makes one process behave like a parent.
See Parent - custom parenting of processes
Thank you for this great and deadly blog-series!








