This thread should go to Linux programming section!
After you fork(), you have two DIFFERENT processes (not threads). So examining your code
Code:
int main(void)
{
/* you have on process */
if(fork())
fork();
/* you have three processes */
printf("I am pid %d!\n", getpid());
return 0;
}
or
Code:
process1
|
fork
|
--------+---------
| |
v v
process1 process2
(parent) (child)
printf() printf()
return 0; return 0;
The above is a normal fork(),in your program you fork() two times! So, you have one parent and two children. The numbers are PIDs of parent and children processes.
I suggest you to use switch or else-if statements to distingusish the processes.