5 ms·
waitpid is inherently racy. wait is covered by This can not be achieved using a pattern equivalent to { ... }. The parent process itself might be abrup
by matklad 3y ago
waitpid is inherently racy. wait is covered by
This can not be achieved using a pattern equivalent to { ... }.
The parent process itself might be abruptly killed, and the finally blocks / destructors / atexit hooks are not run in this case.
- pjmlp 3y agoThat pattern is wrong. You call waitpid() directly, configured for timeout, and if it returns with error that the process is no longer available, then act upon it.
- matklad 3y agoTwo scenarios where this breaks: * parent process is killed after it forks, but before it calls `waitpid`. Nothing even attempts to kill&wait for the child * parent process is killed after it issues `waitpid` syscall. The child continues to happily execute while the parent is dead.
- pjmlp 3y ago- waitpid returns after timeout, assume the process is dead, collect all zombie processes just in case. - yeah this one is a bummer, write the child pids, collect them via a watchdog process