I'm writing a daemon process to execute programs and then restart them if they exit with a status of something other than EXIT_SUCCESS; but these programs will probably not want to be daemon processes themselves. If I use fork() and then call execv() will the new child process be a daemon process too?
I tried running firefox and it didn't work; so I'm guessing no; in which case, how can I start the child processes as normal processes?
To be a "daemon" in UNIX all it means is that the process closes stdin, stdout, and stderr,
and then backgrounds itself by doing a fork()/exec() and allowing the parent process to
exit normally.
@jsmith,
I guess the only way to do this would be to dup() stdin, stdout and stderr, store those somewhere, and then re-open them when I create another child process (one that doesn't need to be a deamon. Would this work? Is there a better way of doing it?
It's based on the MINIX 3 "reincarnation server." It's a process that can detect driver and server problems or crashes and then restarts or removes the offending driver. It's why MINIX rarely crashes. Unless there's an error with the reincarnation server itself, the file system server or the kernel, it pretty much never crashes because the drivers are all outside of the kernel (except the CLOCK and SYSTEM tasks). I got Tanenbaum and Woodhull's book a few days ago :)
My version runs like a UNIX daemon. My plan is to have it in /etc/rc.d/ and start it from /etc/rc.conf on boot. Then it'll parse a file (/etc/respawntab) and run all of the processes within the file. Then, if any of the processes is terminated with a status other than EXIT_SUCCESS it gives the option of restarting the process.