1

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.

  • 1
    I woud get the new PID from a /run/name_of_process.pid file instead. – Rui F Ribeiro Aug 29 '18 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. – Ben Gribaudo Aug 29 '18 at 18:30
  • 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. – Mark Plotnick Aug 29 '18 at 18:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.