Confused with fork & vfork
- From: "Samrat Kannikar" <samrat.kannikar@xxxxxx>
- Date: Fri, 30 Nov 2007 12:06:44 +0530
I have 2 C programs where 1 program uses fork and second uses vfork. The
behaviuor of the program has confused me...
int a; //uninitialized data segment
int main()
{
pid_t pid;
pid = vfork();
if(pid == 0) //child
{
a = 10;
printf("\n Child Process a=%d \n",a);
exit(0);
}
else if(pid > 0) //parent
{
printf("\n Parent Process a=%d \n",a);
exit(0);
}
else
{
printf("\n Could not create child process \n");
}
}
Since vfork is used child executes first and prints 10. But parent process
also prints 10. Since vfork uses COW and child process is changing value of
a should a new page be not allocated to the child process and value of
parent must still be 0?
When i replace vfork by fork the value of a in parent is 0 & in child is 10.
Im confused with this. Plz tell me what is happening?
Regards,
Samrat
.
- Follow-Ups:
- Re: Confused with fork & vfork
- From: Joe Pfeiffer
- Re: Confused with fork & vfork
- Prev by Date: anjuta and glade : empty window
- Next by Date: Re: How Can I call close() for all
- Previous by thread: anjuta and glade : empty window
- Next by thread: Re: Confused with fork & vfork
- Index(es):
Relevant Pages
|
|