#include <stdio.h>
int num = 0;
int main(int argc, char*argv[]){
printf("common line\n");
printf("%d", num);
int pid;
pid = fork();
if(pid == 0){ /*child*/
num = 1;
} else if(pid > 0){ /*parent*/
num = 2;
}
printf("%d\n", num);
}
I above program, common line string is shown single time in output. But "0" is comming twice in the results.
Coming outputs:
common line
01
02
OR
common line
02
01
As per my understanding, 0 should come only once?