#include<stdio.h>
#include<sys/types.h>
int main()
{
pid_t pid;
if((pid=vfork())<0)
{
perror("FORK ERROR");
exit(1);
}
if(pid==0)
{
printf("[CHILD] child id : %d\n" , pid);
_exit(1);
}
else
{
printf("[PARENT] process id : %d\n" , pid);
exit(1);
}
}
The above program uses vfork to create process. So , address space is shared between parent and child. It implies that there is only a single copy of pid variable. But when i print the pid variable in child it gives 0. The same pid variable in parent gives the process id of the child. How is this possible if there is only one copy of pid variable.