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
In reply to Re^2: fork(): when parent exits, what happens to child?
by jethro
in thread fork(): when parent exits, what happens to child?
by 7stud
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |