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
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