Question: For this and next question, assume the following code successfully compiles and runs on a modern linux machine ( assume any irrelevant details have been

For this and next question, assume the following code successfully compiles and runs on a modern linux machine (assume any irrelevant details have been omitted; also assume that all required header files are included):
int main(int argc, char** argv)
{
int a =0;
pid_t child_pid;
child_pid = fork();
a++;
if(child_pid ==0)
{
pid_t grand_child_pid;
grand_child_pid = fork();
a++;
}
else
{
a++;
}
printf("Hello!
");
printf("a is %d
", a);
wait(NULL);
return 0;
}
Assuming fork() never fails, how many times will the message "Hello!
" be displayed?
1
3
4
2
2.What will be the smallest value of "a" displayed by the program?
3
4
1
2

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!