Re: fork/system/child processes

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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,
-- 
Iain Buchanan <iain@xxxxxxxxxxxxxxxxxxx>

Assembly language experience is [important] for the maturity
and understanding of how computers work that it provides.
		-- D. Gries

Attachment: signature.asc
Description: This is a digitally signed message part


[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux