Okay I am working with the following C/C++ code in linux:
int main() {
printf("hello");
Pid = fork();
if (pid > 0)
printf("I’m the parent!");
else
printf("I’m the child");
return 0;
}
My notes from my CS prof say the following:
After a new child process is created, both processes will execute the next instruction following the
fork()system call. Please note that Unix will make an exact copy of the parent's address space and give it to the child. Therefore, the parent and child processes have separate address spaces.
For this reason, I am extremely confused as to why it would not only output the current directory again but also the "hello" again? the only possible reason I could think that it would do this is the line that says it "copies the address space" is simply re-running all the commands before the fork but that doesn't make any sense.
