Fork & Children Processes

souper (5)
The fork() function is a little fuzzy to me. Particularly when you have if/else statements like the one below:

if(fork())
printf("I'm the parent with pid: %d\n", getpid());
else
printf("I'm the daughter with pid: %d\n", getpid());

How do both statements get executed exactly? Also, the main question I want to ask is is there any way to be able to specifically control a certain child process.

For example I created two children from a single parent. I want the children to communicate through Shared Memory, Pipes, Sockets, etc. One child has to send a particular message to the other and vice versa. The messages are distinct and the necessary pid of the "sender" has to be included in the message, which is where I get stuck. Is there any way of doing this? Any help is greatly appreciated.

Jeff
Registered users can post here. Sign in or register to post.