Question: Write a program which does the following steps - Opens a file named write.txt and writes hello world to this file. - Forks a Child

Write a program which does the following steps

- Opens a file named write.txt and writes "hello world" to this file.

- Forks a Child process

this child process then redirects stdout into write.txt

- Parent process does no redirection (i.e. it should still print to stdout)

- Both parent and child print their PID using printf()

- Child process created above

reads the entire contents from write.txt restore standard output to screen then prints the contents of write.txt to stdout. - Both parent and child print their PID using printf() at the end.

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 Programming Questions!