Question
Fork Consider the program below that runs without errors: int main() { int i; printf(Mangoes ); int r = fork(); printf(Apples ); if (r ==
Fork
Consider the program below that runs without errors:
int main() {
int i;
printf("Mangoes ");
int r = fork();
printf("Apples ");
if (r == 0) {
printf("Oranges ");
int k = fork();
if (k >= 0) {
printf("Bananas ");
}
} else if (r > 0) {
printf("Peaches ");
for(i = 0; i < 3; i++) {
if ((r = fork()) == 0) {
printf("Pears ");
exit(0);
printf("Nectarines ");
} else if (r > 0) {
printf("Plums ");
}
}
}
}
1. In the table below, indicate how many times the name of each fruit is printed.
Fruit name | Times printed |
Mangoes |
|
Apples |
|
Oranges |
|
Bananas |
|
Peaches |
|
Pears |
|
Nectarines |
|
Plums |
|
2. Several orderings of the fruit names are possible valid output. Some of these orderings even have the unix prompt displaying before the final fruit name (or names). Explain why this happens.
3. Not all of the fruit names could appear after the prompt in a valid output. For example the word Mangoes will never appear after the prompt. List all the fruit names that could occur after the prompt.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started