> (pid_t)-1, what does this do? Type cast the -1 to pid_t?
Yes, just on the off-chance that pid_t isn't the same as an int.

> Can I run fork in a function other than main?
Sure you can. The examples just make it simple.
Actually, I can't think of anything which "must be done in main, and only main".

And yes, you can have Grand Parent, Parent, Child relationships if you want. Though you need to draw out what you want on paper, and comment the code carefully to avoid self-inflicted damage.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.