in Operating System
51 views
0 votes
Consider the following code fragment executed by a process of PID=1055.

int main()
{
int a=5;
if (fork() == 0)
{ a = a + 5;
b= getppid();
printf(“%d, %d \n”, a, b);
}
else
{ c = a - 5;
d= getpid();
printf (“%d, %d \n”, c, d);
}
return 0;
}

Write the output of a, b, c, d?
in Operating System
51 views

Subscribe to GO Classes for GATE CSE 2022

1 Answer

0 votes

After execution of if() condition we have a Parent and a Child process.

Parent process will execute else part, so c = 0, d = 1055 and

Child process will execute if part , so a = 10, b = 1055

Note : Both parent and child process will have same logical address (Pid) but different physical addresses.

 

 

Related questions