> (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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.