On 25/10/2023 02:19, Greg Wooledge wrote:
At this point I still don't know *why* glibc rewinds stdin intermittently on exit().
Consider a parent process that reads some file. When a specific keyword appears there, it should start a child that parses the same file till another keyword. When the child exits the parent continues reading the the file from the point where the child stopped.
Buffered input in child may cause offset beyond the point where the child faced terminating keyword. It is reasonable to rewind the input file to the position just after last string actually processed by the child.
So flush on exit looks like a way to make applications a bit more reliable. However the price is that developers must be careful with fork.