简体   繁体   中英

How to monitor a child process state in Linux

I have a control service that its functionality is to manage another process in the system. I have to run this process, re-run it if it's unexpectedly closed, and close it manually upon user request.

Can you please advise me how to do that in Linux? should I save the child process PID and check its state periodically? can I register to some system events that will notify me if the application running state has been changed?

Thanks in advance.

should I save the child process PID and check its state periodically?

No, if the child exits, the parent will receive signal SIGCHLD , so you can install signal handler to react on this event.

See sigaction(2) for how to install a signal handler, see signal(7) for general information about signal.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM