Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Would PR_SET_CHILD_SUBREAPER help for reliably killing grandchildren? #55

Open
bjorn3 opened this issue Sep 6, 2022 · 2 comments
Open

Comments

@bjorn3
Copy link

bjorn3 commented Sep 6, 2022

Maybe something like forking, calling prctl(PR_SET_CHILD_SUBREAPER) in the forked process and then running the command from this forked process would help with reliably killing grandchildren. I think you could then kill all the command with all children and grandchildren by killing all children of the forked process until no children are left. Normally when a parent process dies, all children get init as new parent. PR_SET_CHILD_SUBREAPER instead causes the process which called it to be the new parent for all childprocesses and their children of the process using this syscall if a parent process dies. This also means that this process is responsible for calling wait on all zombie childprocesses when it receives SIGCHLD. I haven't actually checked if this scheme works though.

Edit: others also suggested this on HN. Should have scrolled down a bit. 🤦

@matu3ba
Copy link

matu3ba commented Dec 11, 2024

more complete Linux only solution explained in https://catern.com/ideas.html implemented in https://github.com/catern/supervise

@oconnor663
Copy link
Owner

I could be mistaken, but my impression is that using PR_SET_CHILD_SUBREAPER means the process needs to be prepared to handle SIGCHILD from grandchild processes. But my assumption has been that setting / relying on global signal handllers is a non-starter for a library, which might need to run in-process with any number of other libraries with similar ideas. Curious to get folks' thoughts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants