What are the odds of a PID getting assigned to the same process after a wraparound? [closed]

StackOverflow https://stackoverflow.com/questions/21760582

  •  11-10-2022
  •  | 
  •  

Pergunta

I understand that /proc/* contains directories that are actually PIDs.

I have a custom process that is killed and spawned every few minutes.

What are the chances of a PID (for example, 1009) getting reused by the custom process? (After wrapping around pid_max)

Is it likely enough to happen that my code should deal with it?

Foi útil?

Solução 2

"What are the odds" is a statistics question, and the answer depends on how many other processes there are, and how often they fork() and how often they exit(), so the exact answer is difficult to calculate. Anywhere between "almost impossible to happen" and "nearly guaranteed to happen every minute."

If the question is "could this happen in my lifetime and should I handle that in my code" then the answer is yes.

Outras dicas

High enough that you should expect it to happen and be prepared to deal with it. The actual probability will of course depend on how often other processes are being created on your system. There is certainly no guarantee that it won't happen, though, so you must assume that it will.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top