This isn't fedora-specific...
I have an application that MUST run forever.... if it crashes, dies, ends for any reason I want it to start again.
One exception, I want to be able to stop it with a kill term...
So, my solution is a very simple loop...
for (;1==1;) { system("command-to-run"); #do some sort of logging to show command-to-run ended unexpectedly }
If my loop program gets a sig term, I want to trap that, kill the child process and then exit gracefully.
I can trap the signal, but how do I get the pid of the child process (command-to-run)
I tried: for (;1==1:) $newpid = fork; if ($newpid) { # parent... wait; #log unexpected end of command-to-run } else { # child ... system(command-to-run); exit; } }
but in that case $newpid is the pid of the child that issues "system"... not the pid of "command-to-run". (expected... but not what I want/need.)
Any suggestions?
Thank you, Don
you probably could do a if program ends then send signal stop or term then system run program
but i forgot if u can do another then
OR
loop while program is runining = true then do nothing if = false then run signal term
then just put a program exec to start the program
loop
hope this info is close to correct im not too far into my student programming career lol
On Tue, 2003-12-02 at 22:23, Don wrote:
This isn't fedora-specific...
I have an application that MUST run forever.... if it crashes, dies, ends for any reason I want it to start again.
One exception, I want to be able to stop it with a kill term...
So, my solution is a very simple loop...
for (;1==1;) { system("command-to-run"); #do some sort of logging to show command-to-run ended unexpectedly }
If my loop program gets a sig term, I want to trap that, kill the child process and then exit gracefully.
I can trap the signal, but how do I get the pid of the child process (command-to-run)
I tried: for (;1==1:) $newpid = fork; if ($newpid) { # parent... wait; #log unexpected end of command-to-run } else { # child ... system(command-to-run); exit; } }
but in that case $newpid is the pid of the child that issues "system"... not the pid of "command-to-run". (expected... but not what I want/need.)
Any suggestions?
Thank you, Don
-- fedora-list mailing list fedora-list@redhat.com To unsubscribe: http://www.redhat.com/mailman/listinfo/fedora-list
On Wed, 2003-12-03 at 14:53, Don wrote:
This isn't fedora-specific...
I have an application that MUST run forever.... if it crashes, dies, ends for any reason I want it to start again.
Ok, 1. assume (language == perl :) 2. This won't make sure your program runs forever, because the parent could be killed 3. If you're not worried about the parent being killed, then why don't you just use bash? or a simple loop? eg
(bash) $ while :; do ./my-daemon.pl && break; echo "oops, it died"; sleep 1; done
(perl loop) while (1) { `my-daemon.pl`; print "oops, it died\n"; }
They'll all die with a ctrl-c (make sure my-daemon.pl exits 1 on a sig term, 0 on everything else)
[snip]
I tried: for (;1==1:) $newpid = fork; if ($newpid) { # parent... wait; #log unexpected end of command-to-run } else { # child ... system(command-to-run); exit; } }
You should use fork with exec, not system. Then if it behaves anything like the C-style exec, just kill the child pid from the parent, to kill the process you just exec'd.
HTH,
On Wed, 2003-12-03 at 16:23, Iain Buchanan wrote: [oops!]
They'll all die with a ctrl-c (make sure my-daemon.pl exits 1 on a sig
^^^^^^ sig term
On Tue, 2003-12-02 at 22:53, Iain Buchanan wrote:
You should use fork with exec, not system. Then if it behaves anything like the C-style exec, just kill the child pid from the parent, to kill the process you just exec'd.
That's EXACTLY what I wanted.... and I was so close.... :-)
Thanks, Don
Don wrote:
This isn't fedora-specific...
I have an application that MUST run forever.... if it crashes, dies, ends for any reason I want it to start again.
try daemontools - http://cr.yp.to or put it on /etc/inittab.