[uClinux-dev] Question about fork and vfork

Friedrich, Lars lars.friedrich at wago.com
Wed Aug 3 17:38:54 EDT 2005


> 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.

If you implement race conditions, the result is not consistent.
This is normal behaviour and has nothing to do with the vfork
system call.

Best regards,
Lars Friedrich



More information about the uClinux-dev mailing list