252 views
0 votes
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?

1 Answer

0 votes
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

0 votes
0 votes
1 answer
2
[ Jiren ] asked Mar 5, 2023
334 views
0 votes
0 votes
1 answer
3
[ Jiren ] asked Mar 5, 2023
225 views
0 votes
0 votes
2 answers
4
[ Jiren ] asked Mar 5, 2023
233 views