onstop4

onstop4

Worried About PID Reuse

Hello, I’m new to Elixir, and I keep thinking about a hypothetical scenario that could be problematic due to the way PIDs are generated. Let’s say that process A obtains the PID of process B and is going to send a message to process B. In the meantime, however, process B dies and process C starts with the same PID as process B. If process A sends the message to the PID that is now associated with process C, then process C will crash or cause other problems. Because of this, is there any way to prevent process C from receiving a message intended for process B?

I think that this is very hypothetical since it’s unlikely for a newly created process to have the same PID as a process that just died. However, as far as I know, the BEAM will eventually reuse PID numbers, and if many processes are running at the same time, then it seems possible that a PID belonging to a process that just died will eventually be used for a new process. Because of this, is there any way to prevent the scenario described before?

Thank you.

Marked As Solved

rvirding

rvirding

Creator of Erlang

It can’t happen. The numbers themselves don’t really mean much and the pid is “just” a reference to an internal data structure.

Actually the firs number has some meaning, if it is 0 then it is a pid referring to a process on this node, otherwise it refers to a process on another node.

A bit of ancient history. Back in the really old days the other numbers did mean something: the 2nd number was the index into the process table of that process and the 3rd was the number of times this index had been used. No risk of reuse then either.

11
Post #3

Also Liked

arcyfelix

arcyfelix

I think your worry makes sense, but the probability of that happening, especially consistently is almost zero.

I just spotted someone has explained that before more in detail (https://stackoverflow.com/a/46140414/22746062).

PS. Elixir is based on Erlang so the answer on Stackoverflow applies to Elixir.

Where Next?

Popular in Questions Top

lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
JulienCorb
I am trying to implement my new.html.eex file to create new posts on my website. new.html.eex: <h1>Create Post</h1> <%= ...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New

Other popular topics Top

Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
chrismccord
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
johnnyicon
Hi all, I’ve just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I’m trying to use Postgres...
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 39523 209
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
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New

We're in Beta

About us Mission Statement