LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This 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


Reply
  Search this Thread
Old 02-19-2012, 10:55 PM   #1
tom_mee
LQ Newbie
 
Registered: Feb 2012
Distribution: fedora, red hat, centOS
Posts: 12

Rep: Reputation: 0
Question 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?
 
Old 02-20-2012, 01:30 PM   #2
ButterflyMelissa
Senior Member
 
Registered: Nov 2007
Location: Somewhere on my hard drive...
Distribution: Manjaro
Posts: 2,766
Blog Entries: 23

Rep: Reputation: 411Reputation: 411Reputation: 411Reputation: 411Reputation: 411
...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
 
Old 02-20-2012, 09:48 PM   #3
tom_mee
LQ Newbie
 
Registered: Feb 2012
Distribution: fedora, red hat, centOS
Posts: 12

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by Thor_2.0 View Post
...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)?

Last edited by tom_mee; 02-20-2012 at 09:58 PM.
 
Old 02-21-2012, 12:07 AM   #4
Valery Reznic
ELF Statifier author
 
Registered: Oct 2007
Posts: 676

Rep: Reputation: 137Reputation: 137
Quote:
Originally Posted by tom_mee View Post
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?
 
Old 02-21-2012, 07:45 PM   #5
tom_mee
LQ Newbie
 
Registered: Feb 2012
Distribution: fedora, red hat, centOS
Posts: 12

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by Valery Reznic View Post
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Java Daemon Dies Quietly dswanson99 Linux - Software 11 03-30-2010 07:50 AM
daemon dies !!!!!!!! sachinh Linux - General 5 12-05-2007 01:38 AM
Bash child process in foreground while parent dies kborgnis Programming 3 11-09-2007 06:50 AM
TCL/expect - parent hangs when child dies Hewson Programming 1 03-27-2007 08:44 PM
pppd daemon dies, return value of 4 eed Linux - Networking 0 02-17-2004 09:41 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 08:34 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration