When a process is started, Linux picks a PID from a pool.
I wonder whether it is possible to tell Linux not to pick certain PID without rebooting the machine as I want to disable certain PID from being picked for probably 2 seconds, and then I will lift that restriction.
Use case
I have like 20 C++ applications running in parallel and each of them will create a named shared memory segment called process.[pid]
. And since each application could crash (in case there is a bug), then I don't get a chance to clean up (removing process.[pid]
or to be more precise, shm_unlink()
the segement). Due to limited memory, I would like to reclaim the resource if I find the process associated with process.[pid]
has died already. And so I was planning to write a script (with cron
to kick it in periodically) to parse the named shared memory segment files and then clean up. But I am afraid when my script is about to delete process.1234
and OS assigns PID 1234 to my newly started C++ application, which will attempt to create process.1234
, and then right after it is created, OS context switches to my script to delete process.1234
.
Thanks.
RemoveIPC=
to handle this automatically?process.[pid]
. Hence, if my script can parse the name and does something likeif pid is not running; then delete the segmenet
, and the OS picks the PID for the next process (my application again) to use between theif
andthen
statement, then my application will attempt to create, and context switch back to the script, the script deletes the segment just created, and then context switch back to my application. Then, the whole thing is wrong.RemoveIPC=
might not work as my application will create multiple named segments but some should stay forever. Some should be deleted after the process crashes, or properly exits.