How to control the service life

I have a problem, I have control executables that control several processes, and if someone died, he will restart it. In windows, we do with WaitFOrMultipleObject, where the process handle is passed in the handle array. If any process dies, we get a WaitForMultipleObject confirmation.

Now we have to implement it on Linux. How do we do this? Waiting only works for one process identifier, and for now, we need to control several processes.

+3
source share
2 answers

It looks like you are looking for process groups . You can waitpid(2)for a process group using -pidgroup(i.e., a negative pid value) as the pid value in the call, or -1to wait for any child process.

+1
source

This is one of the places where Unix crashes - there really needs to be the concept of a file descriptor for a process that can be passed to select(which is equivalent to Unix WaitForMultipleObjects); but this is not so.

SIGCHLD. wait4 waitpid ( , , wait, ) , WNOHANG, 0. PID . , . ( - waitpid write) , , " " sigsuspend .

+1

Source: https://habr.com/ru/post/1788293/


All Articles