Question: Questions are referring to using C language and a Linux Virtual Machine terminal. 4. Compile the exact program below (no modifications). (a) First, run the

Questions are referring to using C language and a Linux Virtual Machine terminal.

4. Compile the exact program below (no modifications).

Questions are referring to using C language and a Linux Virtual Machine

(a) First, run the program with output going to the terminal as usual.

./a.out

Observe the output, and explain how each line you see was generated, explaining the reason behind any duplicate lines. Use a fork diagram.

(b) Next, run it with output redirected to a file, and see whats in the file.

./a.out > output.txt

cat output.txt

Examine the output again, this time stored in the file output.txt. For a normal program, the contents of the output.txt file here should be identical to the output in (a) above.

(c) What difference do you see from question b?

(d) Explain the reason behind the difference. Specifically, explain all the duplicate lines.

#include #include int main(void) { char wmsg [] = "write() before fork() "; write(STDOUT_FILENO, wmsg, sizeof(wmsg) - 1); printf("printf() before fork() "); fork(); printf("printf() after fork() "); sleep(1); return 0

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!