Variables after fork
问题 Here is a code: int i=0; pid_t pid; puts("Hello, World!"); puts(""); pid = fork(); if(pid) i=42; printf("%p\n", &i); printf("%d\n", i); puts(""); And output Hello, World! 0x7fffc2490278 42 0x7fffc2490278 0 Program print Hello, World! one time, so child process wasn't start from the beginning and it wasn't re-define variables. Adresses of variables are same. So they are same. But I change i's value in parent process which is executed first, it didn't change for child process. Why? 回答1: