Quote:
Originally Posted by
SirSalt
Alright, thank you for clarifying that
---------- Post updated 12-18-16 at 09:20 PM ---------- Previous update was 12-17-16 at 10:28 PM ----------
As I meditated on what you said, I thought of something. In your #3 explanation, would the tty be process "A"? Or would the tty in your example be process "B"? I guess I have a slight and subtle confusion about using "fork" and "forked" in the verb context. When you said "You actually forked a child ("B")", was forking the child a result of calling fork() in process "A", or calling fork() in process "B"? I hope you can see what I'm getting at here. :P
In #3, A calls
fork(). At that point you have processes A and B. Then B calls
fork(). At that point you have processes A, B, and C all running the same instructions. Then B calls
exit() leaving you with processes A and C running. Then C calls
execl() (or another function from the
exec family) to replace the instructions C was running with the instructions needed to run the daemon. At that point you then have A running the code it was running and you have C running your daemon.
Note that since C was a child of B and B exited, A cannot use
wait() to determine whether or not C is still running and cannot retrieve the exit status of C using
wait(). (Grandparents do not become the parents of their children's orphaned children when their children die before their grandchildren.)