Given the code below:
int main() { int pid; pid=vfork(); if(pid==0) printf("child\n"); else printf("parent\n"); return 0; }
In the case of vfork (), the address space used by the parent process and the child process will be the same, so there must be one copy of the pid variable. Now I cannot understand how this pid variable can have two values ββreturned by vfork () , i.e. Zero for child and zero for parent?
In the case of fork (), the address space is also copied, and in each child and parent instance there are two copies of the pid variable, so I can understand that in this case two different copies can have different values, fork () is returned, but it cannot understand in the case of vfork () , how does pid have two values ββreturned by vfork () ?
source share