Consider a parent process P that has forked a child process C in the program…

Consider a parent process P that has forked a child process C in the program below.

int a = 5;
int fd = open(...) //opening a file
int ret = fork();
if(ret >0)
{
close(fd);
a = 6; ...
}
else if(ret==0)
{
printf("a=%d\n", a);
read(fd, something);
}

After the new process is forked, suppose that the parent process is scheduled first, before the child process. Once the parent resumes after fork, it closes the file descriptor and changes the value of a variable as shown above. Assume that the child process is scheduled for the first time only after the parent completes these two changes. What is the value of the variable a as printed in the child process, when it is scheduled next and will the attempt to read from the file descriptor succeed in the child?

  1. A.

     5, Yes

  2. B.

     6, Yes

  3. C.

    5, No

  4. D.

     6, No

Attempted by 157 students.

Sign up free to check your answer

Sign up free

Explore the full course: Isro

Loading lesson…