using vfork() parent process is printing garbage value

57 views Asked by At
int main()
{
    int p,q=20; 
    p=fork();
    if(p==0)
    {
        q=100;
        printf("q=%d\n",q);
    }
    else
    {
        wait(NULL);
        p=vfork();
        if(p==0)
        {
            q=200;
            printf("q=%d\n",q);
        }
        else
        {
            printf("q=%d\n",q);
        }
    }
}

for the parent, the value of q is coming garbage. why? if instead of using vfork(), normal fork() is used then value of q is 20

0

There are 0 answers