How to avoid killing the wrong process caused by linux PID reuse?
I am trying to write a pkill
-like utility that matches processes by searching for a certain string in /proc/pid/environ
and kills them. But the matched process may exit before I can kill it and another process may take its pid. In that case, I will end up killing the new process. Is there a way to avoid this race condition?
Force parent process to be set to init(1) when process is orphaned
I have a process (X) that is spawned by another process (Y). Prior to the spawn, Y set itself as a subreaper (using prctrl PR_SET_CHILD_SUBREAPER). Is there any way a fork from X can skip Y and have its ppid be 1 (init) when X terminates?
Ideally a Linux C api call, but I will take any other option
Force parent process to be init(1)
I have a process (X) that is spawned by another process (Y). Prior to the spawn, Y set itself as a subreaper (using prctrl PR_SET_CHILD_SUBREAPER). Is there any way X (or a fork from X) can skip Y and have its ppid be 1 (init)?