Why not fix process ids?
Why not fix process ids?
Posted Sep 4, 2023 19:21 UTC (Mon) by adobriyan (subscriber, #30858)In reply to: Why not fix process ids? by adobriyan
Parent article: Race-free process creation in the GNU C Library
If kill -TERM is done from /proc/$pid !
$ ./pause &
[1] 41956
$ cd /proc/41956
# double check it is the same process, VERY IMPORTANT
$ cat comm #cmdline
pause
# send signal WITHOUT LEAVING /proc/$pid (VERY IMPORTANT)
$ kill -TERM 41956
# ... and it's gone!
$ cat comm
cat: comm: No such process
Posted Sep 4, 2023 23:15 UTC (Mon)
by mchapman (subscriber, #66589)
[Link]
Between your "cat" and "kill" commands, the process could have exited, been reaped by its parent, and another process could have been forked with PID 41956. By the time you run kill, that PID may not be the same process you thought it was.
Simply holding a reference to the (old) /proc/$PID directory does not prevent the PID from being reused.
Why not fix process ids?