Question: Using your UNIX/LINUX C compiler run the following program with these 3 different options: a) Displaying the output on the screen. b) Directing the output

Using your UNIX/LINUX C compiler run the following program with these 3 different options:

a) Displaying the output on the screen.

b) Directing the output to a file (using ">").

c) Append the output (using ">>") to another file few times.

How many times does the program display "I'm Alive!" for each of the above three cases?

Comment the fflush(stdout) statements out and run the program again. Explain your answer.

Run the program on your machine and on other Linux machines you have access to and compare your findings.

Depending on your compiler you may have to include other header files.

#include

#include

main ()

{

int k;

printf ("Main Process' PID = %d ", getpid());

fflush(stdout);

for (k = 1; k <= 3; k++)

{

fork ();

printf ("k = %d, PPID = %d, pID = %d, I'm Alive! ", k, getppid(), getpid());

fflush(stdout);

}

}

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!