/* This is a program from the book AP on page 194 to test vfork function, According to the defination in the book, vfork will let child process run in the same address space of parent space and parent process will not resume until child process call an exec or exit; Therefore, the result in the below sample should give result before vfork child glob = 11 var = 21 parent glob = 11 var = 21 BUT the sample here seems giving diffrent result, before vfork parent glob = 10 var = 20 child glob = 11 var = 21 WHY ?? */ #include #include #include int glob ; int main(void){ int var; pid_t pid; glob = 10; var = 20; printf("before vfork\n"); if (vfork()== 0 ) { sleep(1); glob++; var++; printf("child glob= %d var= %d\n", glob, var); exit(0); } else { printf("parent glob= %d var= %d\n", glob, var); } }