[uClinux-dev] Question about fork and vfork

David McCullough davidm at snapgear.com
Wed Aug 3 17:42:07 EDT 2005


Jivin edward_shao at wistron.com.tw lays it down ...
> Dear all,
> I have a question about fork() and vfork().
> I known that currently uClinux does not implement fork() and instead it
> implements vfork().
> However I'm wonder why MMU-less CPU can not support truly fork().
> What is the reason ?? (copy-on-write??) :p

Search the uclinux-dev archives,  this has been discussed plenty of
times in greatdetail.

> Another question is I wrote a simple program, the code is listed below
> 
> int main()
> {
>         int var = 1109;
>         pid_t pid;
> 
>         if ((pid = vfork()) < 0) {
>                 fprintf(stderr, "fork failed\n");
>                 exit(1);
>         } else if (pid == 0) {
>                 var++;
>                 _exit(0);
>         }
> 
>         printf("%d\n", var);
>         return 0;
> }
> 
> On my i386 linux box, the program prints 1110;
> However on uClinux (I used ARMulator, linux 2.6.5 and linux-2.6.5-hsc2.patch)
> the result is 1109
> They are not consistency.
> Why uClinux does not implement vfork() like a normal linux kernel?
> Thank you in advanced. :D

It does,  perhaps you need:

	volatile int var = 1109;

as the compiler will not expect it to change underneath it.

Cheers,
Davidm

-- 
David McCullough, davidm at snapgear.com  Ph:+61 7 34352815 http://www.SnapGear.com
Custom Embedded Solutions + Security   Fx:+61 7 38913630 http://www.uCdot.org



More information about the uClinux-dev mailing list