This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

fork() and file descriptors with un-flushed output


Maybe this is an FAQ but I could not find it in it ;-) or in the lists I
searched:

In cygwin, when you fork() process shares file descriptors. If there happens
to be unflushed output in such a shared file descriptor buffer, would that
be output by both processes?

I have some empirical evidence to support this theory. I support cgreen, a C
unit test and mock framework, which runs every test case in its own
processes using fork().

For many years I have seen the effect that when running in a command window
every thing works as expected, But running in Emacs created multiple
outputs. That has not bothered me that much but know I implemented some
further output routines in the reporting code, and everything just blew up!

The test case is run in a separate processes using fork() which then
messages back and then dies. The output from the runner (parent process)
written to the file before the fork() is then output twice.

This behaviour changed to the expected (only printed once) if a fflush() was
added after the printf() in the parent process before the fork. I'm
suspecting this happens because of unflushed output in the file buffer which
is shared by the two processes, first flushed when the child dies, then
flushed by the parent at some point, not only duplicating output, but also
garbling it.

Is this a known behaviour? Unavoidable in cygwin? (Obviously not, if I'm on
the right track with my guesswork...) If it is a bug, will it be fixed?Â



--
View this message in context: http://cygwin.1069669.n5.nabble.com/fork-and-file-descriptors-with-un-flushed-output-tp92349.html
Sent from the Cygwin list mailing list archive at Nabble.com.

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]