Reputation: 6615
I found an interesting problem on the net. I'll reproduce it here for reference.
I'm writing a
daemon
process to execute programs and then restart them if they exit with a status of something other thanEXIT_SUCCESS
; but these programs will probably not want to be daemon processes themselves. If I usefork()
and then callexecv()
will the new child process be a daemon process too?I tried running firefox and it didn't work. So, in which case, how can I start the child processes as normal processes?
The solutions offered in that site somehow doesn't convince me. Any ideas?
Upvotes: 1
Views: 2169
Reputation: 4809
If by daemon process you mean the file descriptors of stdin, stdout and stderr are not connected to any tty or pts, then yes. So just opening something for stdin, stdout and stderr should work.
However, you should have tried it yourself first, firefox (here) opens perfectly with stdin, stdout and stderr redirected to /dev/null
. I think the main thing is that you call execv()
or execve()
and keep the DISPLAY
variable.
Edit
If your asking how to reconnect to the original descriptor destinations then there's at least no portable solution. Obviously you can't reconnect to a pipe. You can however reconnect (under linux at least) to the tty/pts you came from, or even the file (using the /proc
filesystem and readlink()
). You will have to guess the "seek" though (e.g. if the original command was foo 2>> bar
).
Upvotes: 0