paulanthonywilson

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.


Posted via Devtalk (see this thread for details).

Most Liked

ityonemo

ityonemo

this is where the special “exit from parent” is implemented: otp/gen_server.erl at master · erlang/otp · GitHub

the_wildgoose

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

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!

paulanthonywilson

paulanthonywilson

I got round to writing up the parent / child exit signal behaviour. Death, Children, and OTP | The log of Paul Wilson

I’ll link up the blog posts tomorrow. Thanks for pointing out the behaviour change.

paulanthonywilson

paulanthonywilson

Oh, nice. Thanks. So the OTP contract specifies special behaviour for when the parent dies and, of course, GenServers follow that contract. As I was specifically saying this was about OTP processes, then it is relevant. I’ll mention that somewhere.

Where Next?

Popular in Blog Posts Top

thiagoa
Hello everyone, I published the first post of a series which aims to TDD a full application under an Umbrella project. Each post will g...
New
fredwu
Hi folks, I wrote a blog post the other day on how I built my MVP in 3 months whilst having a day job, using Elixir/Phoenix/LiveView. Th...
New
mudasobwa
Blogged about the motivation and reasoning behind my idea to create yet another FSM library. Long story short: I did it in a proper way :...
New
marcin
Hi! :wave: I wanted to refresh my knowledge on how to mix phx.gen.auth with local password users db, as well as OAuth providers such as ...
New
wmnnd
Hey there, I’ve started a little blog series about building and deploying Elixir applications. Now I would like to share with you the f...
New
lawik
Building on other people’s work I bashed things together and suddenly I can know when someone is speaking using Elixir and Membrane.
New
adolfont
Hi, You all probably know that José Valim is Brazilian and that his native language is Portuguese. I, Herminio Torres, Matheus Pesanha a...
New
brainlid
Dialyzer is a tool that you’ve probably heard about in the Elixir community. You may have even used it. However, adding Dialyzer to an ex...
New
ConnorRigby
Just finished a post for Embedded Elixir and I thought it should be cross-posted here: I’ll update this thread as posts get published. ...
New
mudasobwa
Just blogged on the general approach to creating easily extendable applications with plugin support.
New

Other popular topics Top

chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 30048 115
New
yurko
Here are few pieces of (common) Linux knowledge that we use for reasonably small one server apps. We use Ubuntu but this should work for ...
New
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
vac
Hi, I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New

We're in Beta

About us Mission Statement