On Tue, Oct 24, 2023 at 11:01:55PM +0700, Max Nikulin wrote:
> On 24/10/2023 12:18, tom kronmiller wrote:
> > so I unbuffered stdin and that seemed to make it happy.
> 
> It might be performance killer. Even fflush(NULL) before fork() may be
> better.
> 
> https://stackoverflow.com/questions/50110992/why-does-forking-my-process-cause-the-file-to-be-read-infinitely
> "Why does forking my process cause the file to be read infinitely"

Ooh, that's got an *excellent* answer.

> glibc bug report was closed as invalid
> https://sourceware.org/bugzilla/show_bug.cgi?id=23151
> 
> I am curious why macOS behaves differently.

It would have been nice if the glibc developer had explained a bit, but
of course we aren't owed any explanations.

At this point, we can conclude that the bug is in fact in the OP's C
program.  The underlying C compiler, C library, and Linux kernel are
all behaving within specs.

At this point I still don't know *why* glibc rewinds stdin intermittently
on exit().  Apparently Mac OS X doesn't, or at least didn't at the time
the answer was written (2018).  I guess there must be some reason for it,
and it's not just randomly pranking people, even if I don't understand
the reason.

This has been a most educational thread.

Reply via email to