in reply to Re: fork(): when parent exits, what happens to child?
in thread fork(): when parent exits, what happens to child?
If the child actually finished executing, then wouldn't the close() execute on the output file handle, thus flushing the buffer to the file?Yes, but you would have to wait 20 seconds before the child has put out all 10 numbers because of the 'sleep 2' line. When I tried your script and executed the 'cat data1.txt' immmediately or 10 seconds after I got the shell prompt back I saw an empty file. But after 20 seconds the file suddenly had all 10 numbers in it. Because of buffering.
Even if you turn off the buffering you should not expect more than one number every two seconds to arrive in data1.txt. Again because of 'sleep 2'. You could do a 'tail -f data1.txt' to see exactly what is happening in realtime
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: fork(): when parent exits, what happens to child?
by 7stud (Deacon) on Mar 26, 2010 at 18:01 UTC | |
by rowdog (Curate) on Mar 28, 2010 at 03:30 UTC |