Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to monitor process life

Tags:

c++

linux

process

I have a problem, I have a control executables which monitor few process and if anyone died then it will restart it. On windows we are doing with WaitFOrMultipleObject where process handle passed in the array of handle. If any process die we getting acknowledged by WaitForMultipleObject.

Now we have to implement it on Linux. How we will do it? Wait is only work for one process id and while we have to monitor multiple process.

like image 636
CrazyC Avatar asked Jun 03 '26 23:06

CrazyC


1 Answers

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

like image 138
Flexo Avatar answered Jun 06 '26 00:06

Flexo