fork/system/child processes

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

 



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






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

  Powered by Linux