3 ms·
You could do it for a very long time. Folks are mentioning the new pidfd stuff, but that interface is built on much older tricks. In particular, what you could
by cyphar 7y ago
You could do it for a very long time. Folks are mentioning the new pidfd stuff, but that interface is built on much older tricks.
In particular, what you could do is grab a handle to /proc/$pid. This is now called a pidfd, but this works on old kernels too. Then, to check if the process has died you just do a fstatat(2) and see if you get ESRCH -- if you do, the process has died and this will work even if the pid is reused. I think you could use inotify to avoid polling, but I'm not sure.
The main benefit for the new poll support for pidfds is that you can get the exit status. And obviously CLONE_PIDFD has other benefits as well as the incredibly useful feature of pidfd_send_signal(2) which was the first patch sent for Linux 5.1.