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?