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.
/run/name_of_process.pid
file instead.wait
for the process until you want it to. The zombie process retains the pid.