I'd like to introduce a solution for the problem originally described here:
pkillis not an atomic operation, not by a long stretch. In the while since pkill -P 666 foo has determined that pid 667 is the child of 666 named foo (which on e.g. Linux it does by opening and reading multiple files in the /proc fs) until it actually calls the kill(2) system call, the process could've already terminated and its pid could've been already reused.
In order to make
pkill -P XXX operation safe (like transactions in SQL) I'd like to implement the Two Phase Commit Protocol:
- Check if the process is child of
- If "yes", mark the PID of the child process as "DO_NOT_REUSE".
- Check if the process is still the child of
- If "yes", kill the child process, if still possible.
- Remove the
DO_NOT_USEflag for that PID number.
For that purpose, can I mark a PID number as "can not be used"?