I have a monitoring program that I'd like to check on various processes in the system, and know when they terminate. I'd also like to know their exit code, in case they crash. However, my program is not a parent of the processes to be monitored.
In Windows, this is easy: OpenProcess
for SYNCHRONIZE
rights, WaitForMultipleObjectsEx
to wait for any of them to terminate, then GetExitCodeProcess
to find out why it terminated (with NTSTATUS
error codes if the reason was an exception).
But in Linux, the equivalent of these, waitpid
, only works on your own child processes, not unrelated processes. We tried ptrace
, but this caused its own issues, such as greatly slowing down signal processing.
This program is intended to run as root.
Is there a way to implement this, other than just polling /proc/12345
until it disappears?