Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Fundamentals Of Database Management Systems

Authors: Mark L. Gillenson

2nd Edition

0470624701, 978-0470624708

More Books

Students also viewed these Databases questions

Question

2. Identify the purpose of your speech

Answered: 1 week ago