0

Possible Duplicate:
printf anomaly after “fork()”
Using fork with c
fork() branches more than expected?

I have this example of code, but I don't understand why this code print 00000000 and not 000000.

When i=0 , print 00
When i=1 , there is 4 process and it will print 0000.

This is the program:

 main(){
    int i;
    for(i=0; i<2 ;i++){
        fork();
        printf("0");
    }
  }
Community
  • 1
  • 1
user1479376
  • 327
  • 1
  • 2
  • 10
  • 2
    possible duplicate of [printf anomaly after "fork()"](http://stackoverflow.com/questions/2530663/printf-anomaly-after-fork) or [Using fork with c](http://stackoverflow.com/questions/6399145/using-fork-with-c) or many others... – Oliver Charlesworth Jul 01 '12 at 19:57
  • 9
    Your program might be a little more enlightening if it `printf`'d `i` instead of 0. – Robert Harvey Jul 01 '12 at 19:57

0 Answers0