2

I'm looking for a way to temporarily prevent a process ID from being reused.

The man page for NAMESPACES(7) says:

Bind mounting (see mount(2)) one of the files in [/proc/[pid]/ns/] to somewhere else in the filesystem keeps the corresponding namespace of the process specified by pid alive even if all processes currently in the namespace terminate.

It sounds like this mean that bind mounting /proc/[pid]/ns/pid will keep the PID from being released for reuse by the OS. Is that correct?

Context

In short, I'm writing code that works with an arbitrary PID. I'd like to prevent that PID from becoming associated with another process while I'm working with it. This can occur if the first process dies, the PID is released for reuse, then the PID is assigned to a new process. The first process dying isn't a problem; the PID pointing to a different process while my code works with the PID is a problem.

3
  • 1
    I woud get the new PID from a /run/name_of_process.pid file instead. Aug 29, 2018 at 15:59
  • Actually, I'm not interested in the new process. :-) If my code starts working with, say, PID 123 and the associated process dies while my code is executing, I want to be sure that PID 123 doesn't end up pointing to another process. Having the PID change which process it points to while my code executes will cause problems. Aug 29, 2018 at 18:30
  • 1
    It may be easier to ensure that the parent of the process in question does not wait for the process until you want it to. The zombie process retains the pid. Aug 29, 2018 at 18:52

0

You must log in to answer this question.

Browse other questions tagged .