* vfork implementation...
@ 2006-06-14 9:41 Abu M. Muttalib
2006-06-14 9:46 ` Gleb Natapov
2006-06-14 10:18 ` Mel Gorman
0 siblings, 2 replies; 7+ messages in thread
From: Abu M. Muttalib @ 2006-06-14 9:41 UTC (permalink / raw)
To: linux-mm
Hi,
This mail is intended for Robert Love, I hope I can find him on the list.
Please refer to Pg 24 of chapter 2 of Linux Kernel Development.
As mentioned in the description of vfork call, it is said that child is not
allowed to write to the address space, but in the following example its not
so. The child is able to write to the process address space. This program
was tested with Linux Kernel 2.6.9. Why is it so?
fork.c
----------------------------------------------------------------------------
---------------------------------------
#include <stdio.h>
unsigned char *glob_var = NULL;
void main()
{
int pid = -8,i;
pid = vfork();
if(pid < 0)
printf("\n FORK ERROR \n");
if(pid == 0)
{
unsigned char * local_var = NULL;
local_var = (unsigned char *)malloc(5);
strcpy(local_var,"ABCD");
glob_var = local_var;
printf("\nCHILD :Value of glob_var is %X local_var is %X glob_var is %c
\n",glob_var,local_var,*glob_var);
for(i=0;i<4;i++)
{
printf("\n CHAR is %c \n",glob_var[i]);
}
printf("\nCHILD1 :Value of glob_var is %X %c\n",glob_var,*(glob_var));
}
if(pid > 0)
{
printf("\nParent : Value of glob_var is %X %c\n",glob_var,*(glob_var));
free(glob_var);
printf("\nParent : Value of glob_var is %X %c\n",glob_var,*(glob_var));
exit(0);
}
}
----------------------------------------------------------------------------
---------------------------------------
Regards,
Abu.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: vfork implementation... 2006-06-14 9:41 vfork implementation Abu M. Muttalib @ 2006-06-14 9:46 ` Gleb Natapov 2006-06-14 10:03 ` Abu M. Muttalib 2006-06-14 10:18 ` Mel Gorman 1 sibling, 1 reply; 7+ messages in thread From: Gleb Natapov @ 2006-06-14 9:46 UTC (permalink / raw) To: Abu M. Muttalib; +Cc: linux-mm On Wed, Jun 14, 2006 at 03:11:58PM +0530, Abu M. Muttalib wrote: > Hi, > > This mail is intended for Robert Love, I hope I can find him on the list. > > Please refer to Pg 24 of chapter 2 of Linux Kernel Development. > > As mentioned in the description of vfork call, it is said that child is not > allowed to write to the address space, but in the following example its not > so. The child is able to write to the process address space. This program > was tested with Linux Kernel 2.6.9. Why is it so? > Not allowed and not able are two different things. > fork.c > ---------------------------------------------------------------------------- > --------------------------------------- > #include <stdio.h> > > unsigned char *glob_var = NULL; > > void main() > { > int pid = -8,i; > pid = vfork(); > > if(pid < 0) > printf("\n FORK ERROR \n"); > > if(pid == 0) > { > unsigned char * local_var = NULL; > local_var = (unsigned char *)malloc(5); > strcpy(local_var,"ABCD"); > glob_var = local_var; > printf("\nCHILD :Value of glob_var is %X local_var is %X glob_var is %c > \n",glob_var,local_var,*glob_var); > for(i=0;i<4;i++) > { > printf("\n CHAR is %c \n",glob_var[i]); > } > printf("\nCHILD1 :Value of glob_var is %X %c\n",glob_var,*(glob_var)); > } > > if(pid > 0) > { > printf("\nParent : Value of glob_var is %X %c\n",glob_var,*(glob_var)); > free(glob_var); > printf("\nParent : Value of glob_var is %X %c\n",glob_var,*(glob_var)); > exit(0); > } > } > ---------------------------------------------------------------------------- > --------------------------------------- > > Regards, > Abu. > > -- > To unsubscribe, send a message with 'unsubscribe linux-mm' in > the body to majordomo@kvack.org. For more info on Linux MM, > see: http://www.linux-mm.org/ . > Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a> -- Gleb. -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a> ^ permalink raw reply [flat|nested] 7+ messages in thread
* RE: vfork implementation... 2006-06-14 9:46 ` Gleb Natapov @ 2006-06-14 10:03 ` Abu M. Muttalib 2006-06-14 10:06 ` Gleb Natapov 0 siblings, 1 reply; 7+ messages in thread From: Abu M. Muttalib @ 2006-06-14 10:03 UTC (permalink / raw) To: Gleb Natapov; +Cc: linux-mm I meant, its NOT ALLOWED, still program is ABLE to do so.. hence the wordings.. ~Abu. -----Original Message----- From: owner-linux-mm@kvack.org [mailto:owner-linux-mm@kvack.org]On Behalf Of Gleb Natapov Sent: Wednesday, June 14, 2006 3:16 PM To: Abu M. Muttalib Cc: linux-mm@kvack.org Subject: Re: vfork implementation... On Wed, Jun 14, 2006 at 03:11:58PM +0530, Abu M. Muttalib wrote: > Hi, > > This mail is intended for Robert Love, I hope I can find him on the list. > > Please refer to Pg 24 of chapter 2 of Linux Kernel Development. > > As mentioned in the description of vfork call, it is said that child is not > allowed to write to the address space, but in the following example its not > so. The child is able to write to the process address space. This program > was tested with Linux Kernel 2.6.9. Why is it so? > Not allowed and not able are two different things. > fork.c > -------------------------------------------------------------------------- -- > --------------------------------------- > #include <stdio.h> > > unsigned char *glob_var = NULL; > > void main() > { > int pid = -8,i; > pid = vfork(); > > if(pid < 0) > printf("\n FORK ERROR \n"); > > if(pid == 0) > { > unsigned char * local_var = NULL; > local_var = (unsigned char *)malloc(5); > strcpy(local_var,"ABCD"); > glob_var = local_var; > printf("\nCHILD :Value of glob_var is %X local_var is %X glob_var is %c > \n",glob_var,local_var,*glob_var); > for(i=0;i<4;i++) > { > printf("\n CHAR is %c \n",glob_var[i]); > } > printf("\nCHILD1 :Value of glob_var is %X %c\n",glob_var,*(glob_var)); > } > > if(pid > 0) > { > printf("\nParent : Value of glob_var is %X %c\n",glob_var,*(glob_var)); > free(glob_var); > printf("\nParent : Value of glob_var is %X %c\n",glob_var,*(glob_var)); > exit(0); > } > } > -------------------------------------------------------------------------- -- > --------------------------------------- > > Regards, > Abu. > > -- > To unsubscribe, send a message with 'unsubscribe linux-mm' in > the body to majordomo@kvack.org. For more info on Linux MM, > see: http://www.linux-mm.org/ . > Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a> -- Gleb. -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a> -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a> ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: vfork implementation... 2006-06-14 10:03 ` Abu M. Muttalib @ 2006-06-14 10:06 ` Gleb Natapov 2006-06-14 10:17 ` Abu M. Muttalib 0 siblings, 1 reply; 7+ messages in thread From: Gleb Natapov @ 2006-06-14 10:06 UTC (permalink / raw) To: Abu M. Muttalib; +Cc: linux-mm On Wed, Jun 14, 2006 at 03:33:27PM +0530, Abu M. Muttalib wrote: > I meant, its NOT ALLOWED, still program is ABLE to do so.. hence the > wordings.. > The only thing a process ALLOWED to do after vfork() is exec(), but it is ABLE to do whatever it wants to do. I am not ALLOWED to drive while drunk, but I am ABLE to. > ~Abu. > > -----Original Message----- > From: owner-linux-mm@kvack.org [mailto:owner-linux-mm@kvack.org]On > Behalf Of Gleb Natapov > Sent: Wednesday, June 14, 2006 3:16 PM > To: Abu M. Muttalib > Cc: linux-mm@kvack.org > Subject: Re: vfork implementation... > > > On Wed, Jun 14, 2006 at 03:11:58PM +0530, Abu M. Muttalib wrote: > > Hi, > > > > This mail is intended for Robert Love, I hope I can find him on the list. > > > > Please refer to Pg 24 of chapter 2 of Linux Kernel Development. > > > > As mentioned in the description of vfork call, it is said that child is > not > > allowed to write to the address space, but in the following example its > not > > so. The child is able to write to the process address space. This program > > was tested with Linux Kernel 2.6.9. Why is it so? > > > Not allowed and not able are two different things. > > > fork.c > > -------------------------------------------------------------------------- > -- > > --------------------------------------- > > #include <stdio.h> > > > > unsigned char *glob_var = NULL; > > > > void main() > > { > > int pid = -8,i; > > pid = vfork(); > > > > if(pid < 0) > > printf("\n FORK ERROR \n"); > > > > if(pid == 0) > > { > > unsigned char * local_var = NULL; > > local_var = (unsigned char *)malloc(5); > > strcpy(local_var,"ABCD"); > > glob_var = local_var; > > printf("\nCHILD :Value of glob_var is %X local_var is %X glob_var is %c > > \n",glob_var,local_var,*glob_var); > > for(i=0;i<4;i++) > > { > > printf("\n CHAR is %c \n",glob_var[i]); > > } > > printf("\nCHILD1 :Value of glob_var is %X %c\n",glob_var,*(glob_var)); > > } > > > > if(pid > 0) > > { > > printf("\nParent : Value of glob_var is %X %c\n",glob_var,*(glob_var)); > > free(glob_var); > > printf("\nParent : Value of glob_var is %X %c\n",glob_var,*(glob_var)); > > exit(0); > > } > > } > > -------------------------------------------------------------------------- > -- > > --------------------------------------- > > > > Regards, > > Abu. > > > > -- > > To unsubscribe, send a message with 'unsubscribe linux-mm' in > > the body to majordomo@kvack.org. For more info on Linux MM, > > see: http://www.linux-mm.org/ . > > Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a> > > -- > Gleb. > > -- > To unsubscribe, send a message with 'unsubscribe linux-mm' in > the body to majordomo@kvack.org. For more info on Linux MM, > see: http://www.linux-mm.org/ . > Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a> -- Gleb. -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a> ^ permalink raw reply [flat|nested] 7+ messages in thread
* RE: vfork implementation... 2006-06-14 10:06 ` Gleb Natapov @ 2006-06-14 10:17 ` Abu M. Muttalib 2006-06-14 10:16 ` Gleb Natapov 0 siblings, 1 reply; 7+ messages in thread From: Abu M. Muttalib @ 2006-06-14 10:17 UTC (permalink / raw) To: Gleb Natapov; +Cc: linux-mm HI, Should the wording be interpreted as "should not write"? ~Abu. -----Original Message----- From: Gleb Natapov [mailto:gleb@minantech.com] Sent: Wednesday, June 14, 2006 3:37 PM To: Abu M. Muttalib Cc: linux-mm@kvack.org Subject: Re: vfork implementation... On Wed, Jun 14, 2006 at 03:33:27PM +0530, Abu M. Muttalib wrote: > I meant, its NOT ALLOWED, still program is ABLE to do so.. hence the > wordings.. > The only thing a process ALLOWED to do after vfork() is exec(), but it is ABLE to do whatever it wants to do. I am not ALLOWED to drive while drunk, but I am ABLE to. > ~Abu. > > -----Original Message----- > From: owner-linux-mm@kvack.org [mailto:owner-linux-mm@kvack.org]On > Behalf Of Gleb Natapov > Sent: Wednesday, June 14, 2006 3:16 PM > To: Abu M. Muttalib > Cc: linux-mm@kvack.org > Subject: Re: vfork implementation... > > > On Wed, Jun 14, 2006 at 03:11:58PM +0530, Abu M. Muttalib wrote: > > Hi, > > > > This mail is intended for Robert Love, I hope I can find him on the list. > > > > Please refer to Pg 24 of chapter 2 of Linux Kernel Development. > > > > As mentioned in the description of vfork call, it is said that child is > not > > allowed to write to the address space, but in the following example its > not > > so. The child is able to write to the process address space. This program > > was tested with Linux Kernel 2.6.9. Why is it so? > > > Not allowed and not able are two different things. > > > fork.c > > -------------------------------------------------------------------------- > -- > > --------------------------------------- > > #include <stdio.h> > > > > unsigned char *glob_var = NULL; > > > > void main() > > { > > int pid = -8,i; > > pid = vfork(); > > > > if(pid < 0) > > printf("\n FORK ERROR \n"); > > > > if(pid == 0) > > { > > unsigned char * local_var = NULL; > > local_var = (unsigned char *)malloc(5); > > strcpy(local_var,"ABCD"); > > glob_var = local_var; > > printf("\nCHILD :Value of glob_var is %X local_var is %X glob_var is %c > > \n",glob_var,local_var,*glob_var); > > for(i=0;i<4;i++) > > { > > printf("\n CHAR is %c \n",glob_var[i]); > > } > > printf("\nCHILD1 :Value of glob_var is %X %c\n",glob_var,*(glob_var)); > > } > > > > if(pid > 0) > > { > > printf("\nParent : Value of glob_var is %X %c\n",glob_var,*(glob_var)); > > free(glob_var); > > printf("\nParent : Value of glob_var is %X %c\n",glob_var,*(glob_var)); > > exit(0); > > } > > } > > -------------------------------------------------------------------------- > -- > > --------------------------------------- > > > > Regards, > > Abu. > > > > -- > > To unsubscribe, send a message with 'unsubscribe linux-mm' in > > the body to majordomo@kvack.org. For more info on Linux MM, > > see: http://www.linux-mm.org/ . > > Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a> > > -- > Gleb. > > -- > To unsubscribe, send a message with 'unsubscribe linux-mm' in > the body to majordomo@kvack.org. For more info on Linux MM, > see: http://www.linux-mm.org/ . > Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a> -- Gleb. -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a> ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: vfork implementation... 2006-06-14 10:17 ` Abu M. Muttalib @ 2006-06-14 10:16 ` Gleb Natapov 0 siblings, 0 replies; 7+ messages in thread From: Gleb Natapov @ 2006-06-14 10:16 UTC (permalink / raw) To: Abu M. Muttalib; +Cc: linux-mm On Wed, Jun 14, 2006 at 03:47:07PM +0530, Abu M. Muttalib wrote: > HI, > > Should the wording be interpreted as "should not write"? > Yes. After vfork() a child and a parent share an address space. Whatever a child does to memory is visible in a parent. > ~Abu. > > -----Original Message----- > From: Gleb Natapov [mailto:gleb@minantech.com] > Sent: Wednesday, June 14, 2006 3:37 PM > To: Abu M. Muttalib > Cc: linux-mm@kvack.org > Subject: Re: vfork implementation... > > > On Wed, Jun 14, 2006 at 03:33:27PM +0530, Abu M. Muttalib wrote: > > I meant, its NOT ALLOWED, still program is ABLE to do so.. hence the > > wordings.. > > > The only thing a process ALLOWED to do after vfork() is exec(), but it is > ABLE to do whatever it wants to do. I am not ALLOWED to drive while drunk, > but I am ABLE to. > > > > ~Abu. > > > > -----Original Message----- > > From: owner-linux-mm@kvack.org [mailto:owner-linux-mm@kvack.org]On > > Behalf Of Gleb Natapov > > Sent: Wednesday, June 14, 2006 3:16 PM > > To: Abu M. Muttalib > > Cc: linux-mm@kvack.org > > Subject: Re: vfork implementation... > > > > > > On Wed, Jun 14, 2006 at 03:11:58PM +0530, Abu M. Muttalib wrote: > > > Hi, > > > > > > This mail is intended for Robert Love, I hope I can find him on the > list. > > > > > > Please refer to Pg 24 of chapter 2 of Linux Kernel Development. > > > > > > As mentioned in the description of vfork call, it is said that child is > > not > > > allowed to write to the address space, but in the following example its > > not > > > so. The child is able to write to the process address space. This > program > > > was tested with Linux Kernel 2.6.9. Why is it so? > > > > > Not allowed and not able are two different things. > > > > > fork.c > > > > -------------------------------------------------------------------------- > > -- > > > --------------------------------------- > > > #include <stdio.h> > > > > > > unsigned char *glob_var = NULL; > > > > > > void main() > > > { > > > int pid = -8,i; > > > pid = vfork(); > > > > > > if(pid < 0) > > > printf("\n FORK ERROR \n"); > > > > > > if(pid == 0) > > > { > > > unsigned char * local_var = NULL; > > > local_var = (unsigned char *)malloc(5); > > > strcpy(local_var,"ABCD"); > > > glob_var = local_var; > > > printf("\nCHILD :Value of glob_var is %X local_var is %X glob_var is > %c > > > \n",glob_var,local_var,*glob_var); > > > for(i=0;i<4;i++) > > > { > > > printf("\n CHAR is %c \n",glob_var[i]); > > > } > > > printf("\nCHILD1 :Value of glob_var is %X %c\n",glob_var,*(glob_var)); > > > } > > > > > > if(pid > 0) > > > { > > > printf("\nParent : Value of glob_var is %X > %c\n",glob_var,*(glob_var)); > > > free(glob_var); > > > printf("\nParent : Value of glob_var is %X > %c\n",glob_var,*(glob_var)); > > > exit(0); > > > } > > > } > > > > -------------------------------------------------------------------------- > > -- > > > --------------------------------------- > > > > > > Regards, > > > Abu. > > > > > > -- > > > To unsubscribe, send a message with 'unsubscribe linux-mm' in > > > the body to majordomo@kvack.org. For more info on Linux MM, > > > see: http://www.linux-mm.org/ . > > > Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a> > > > > -- > > Gleb. > > > > -- > > To unsubscribe, send a message with 'unsubscribe linux-mm' in > > the body to majordomo@kvack.org. For more info on Linux MM, > > see: http://www.linux-mm.org/ . > > Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a> > > -- > Gleb. -- Gleb. -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a> ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: vfork implementation... 2006-06-14 9:41 vfork implementation Abu M. Muttalib 2006-06-14 9:46 ` Gleb Natapov @ 2006-06-14 10:18 ` Mel Gorman 1 sibling, 0 replies; 7+ messages in thread From: Mel Gorman @ 2006-06-14 10:18 UTC (permalink / raw) To: Abu M. Muttalib; +Cc: linux-mm On Wed, 14 Jun 2006, Abu M. Muttalib wrote: > This mail is intended for Robert Love, I hope I can find him on the list. > > Please refer to Pg 24 of chapter 2 of Linux Kernel Development. > > As mentioned in the description of vfork call, it is said that child is not > allowed to write to the address space, >From the vfork() manpage; The vfork() function has the same effect as fork(), except that the behaviour is undefined if the process created by vfork() either modifies any data other than a variable of type pid_t used to store the return value from vfork(), or returns from the function in which vfork() was called, or calls any other function before successfully calling _exit() or one of the exec() family of functions. In other words, the child created by vfork() may be *able* to change the address space, but it *should not* because the behaviour is undefined. IIRC, there is no guarantee that the parent will even run again until the child calls exit or exec so a child cannot depend on any behavior from the parent or it could deadlock. Historically, the point of vfork() is to create a process that immediately called exec(). It does not create a copy of the parent address space which was an important optimisation later replaced by Copy-On-Write. -- Mel Gorman Part-time Phd Student Linux Technology Center University of Limerick IBM Dublin Software Lab -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a> ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2006-06-14 10:18 UTC | newest] Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2006-06-14 9:41 vfork implementation Abu M. Muttalib 2006-06-14 9:46 ` Gleb Natapov 2006-06-14 10:03 ` Abu M. Muttalib 2006-06-14 10:06 ` Gleb Natapov 2006-06-14 10:17 ` Abu M. Muttalib 2006-06-14 10:16 ` Gleb Natapov 2006-06-14 10:18 ` Mel Gorman
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox