daemon dies, is restarted. Wants to reclaim previously running child(ren)
Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
daemon dies, is restarted. Wants to reclaim previously running child(ren)
I have written a daemon which keeps track of the children it 'forks' by their PID. Let's say my daemon dies for some reason, but is restarted at a later time. How can I reclaim (ie reparent) the children which may still be running from the previous 'dead' daemon?
...just a simple thought...how about on-disk persistence with an XML file? Make it a sort of domino thing, in that your daemon, when stopped properly, will tip over all the remaining domino blocks before leaving the memory. After a crash, it should not have passed that stage and pick up where it left of by reading its status file...
Just a thought. interesting question. May I follow on with this thread? Thanks.
...just a simple thought...how about on-disk persistence with an XML file? Make it a sort of domino thing, in that your daemon, when stopped properly, will tip over all the remaining domino blocks before leaving the memory. After a crash, it should not have passed that stage and pick up where it left of by reading its status file...
Just a thought. interesting question. May I follow on with this thread? Thanks.
Thor
Thanks Thor - perhaps these details may shed more light onto what I am trying to achieve.
I do have a 'state' file from which I can recover. In this file(amongst other things) are the PID(s) of processes which this process has kicked off. Upon restart, I can determine if the PID's are still running. If they are running, I would re-establish this daemon as the new (reincarnated)parent, so I can get the SIGCLD when they do exit. In order to do this, I believe that I have to be the parent. So, how do I make myself the 'new' parent of the child(ren)?
Thanks Thor - perhaps these details may shed more light onto what I am trying to achieve.
I do have a 'state' file from which I can recover. In this file(amongst other things) are the PID(s) of processes which this process has kicked off. Upon restart, I can determine if the PID's are still running. If they are running, I would re-establish this daemon as the new (reincarnated)parent, so I can get the SIGCLD when they do exit. In order to do this, I believe that I have to be the parent. So, how do I make myself the 'new' parent of the child(ren)?
You can try to use ptrace(PTRACE_ATTACH...) Ugly, but it's the only user-space option that I see. You don't going to write kernel module for this?
You can try to use ptrace(PTRACE_ATTACH...) Ugly, but it's the only user-space option that I see. You don't going to write kernel module for this?
I guess I was hoping there was already a mechanism in place. I figured if 'init' could do it, there's probably a way. I guess some modifications to my package could alleviate the need for this - it would have been a nice clean solution though. I can see why it may not be out there (or at least not advertised) since this mechanism could be exploited and cause security implications. Sort of like giving an axe to a robber, and asking him not to smash any doors or windows.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.