|
fork() help
Hi everybody,
I wanna write a code to understand how fork works.
my target
--------------
-Parent creates a file(called temp) and writes into this file "1".Then it closes the file.
-Then parent creates a child and wait until execution of this child ends.
-Then child opens the same file and reads the last integer in it. Then, it will multiply this integer by 2 and add 1. Then child appends the result as a new line at the end of the file. After closing the file this child will fork another child process and wait until it finishes its execution.
-Then child which calculates the Nth integer will not fork anymore, and return after writing the result into the file.( N can be taken from user )
Thanks a lot men...
|